重构项目 vue2 => vue3 & nuxt2 => nuxt3 遇到的问题

  1. vue3获取组件的上下文

    javascript 复制代码
    import { getCurrentInstance } from 'vue';
    // 获取当前组件实例
    const instance = getCurrentInstance();
     
    // 获取当前组件的上下文,下面两种方式都能获取到组件的上下文。
     //  方式一,这种方式只能在开发环境下使用,生产环境下的ctx将访问不到
    const { ctx }  = getCurrentInstance(); 
    //  方式二,此方法在开发环境以及生产环境下都能放到组件上下文对象(推荐)
    const { proxy }  = getCurrentInstance();  
  2. nuxt3 中使用Vue <component :is="someComputedComponent">语法,需要使用Vue提供的resolveComponent辅助方法,否则无法正常渲染组件,且组件名称必须是字符串而不是变量

    javascript 复制代码
    <template>
      <component :is="clickable ? MyButton : 'div'" />
    </template>
    
    <script setup>
    const MyButton = resolveComponent('MyButton')
    </script>
  3. 警告:Vue received a Component which was made a reactive object. This can lead to unnecessary performance overhead, and should be avoided by marking the component with markRaw or using shallowRef instead of ref.使用"markRaw"方法将组件对象标记为非响应式对象,或者使用"shallowRef"代替"ref"来创建一个浅响应式对象。

    javascript 复制代码
    const componentMap = markRaw(myComponent)
  4. elementPlus与elementUI语法升级

    javascript 复制代码
    //elementUI的descriptions组件插槽语法:
    <el-descriptions>
        <template slot="extra"></template>
    </el-descriptions>
    //elementUI的elementPlus组件语法:
    <el-descriptions>
        <template #extra></template>
    </el-descriptions>
    否则会不展示插槽内容
    javascript 复制代码
    //elementUI的popover组件插槽语法:
     <el-popover>
         <div  slot="reference"></div>
     </el-popover>
     //elementUI的popover组件语法:
      <el-popover>
         <template #reference></template>
     </el-popover>
     否则会报如下警告
相关推荐
爱写代码的小朋友1 天前
破局与重构:人工智能深度赋能基础教育变革研究
人工智能·重构
银色的白1 天前
重构前端代码,定义开发规划
前端·重构
Tianyanxiao1 天前
iOS26 深度解析:WWDC25 重磅系统的设计革新与争议焦点
经验分享·重构·数据分析·设计语言
KKKlucifer2 天前
加密通信 + 行为分析:运营商行业安全防御体系重构
网络·安全·重构
HB17C_22 天前
从线上名片到商业引擎:企业如何用官网重构市场竞争力?
重构
光路科技2 天前
TSN交换机正在重构工业网络,PROFINET和EtherCAT会被取代吗?
服务器·网络·重构
博思云为2 天前
客户案例 | 短视频点播企业海外视频加速与成本优化:MediaPackage+Cloudfront 技术重构实践
重构·音视频
盘古信息IMS2 天前
盘古信息PCB行业解决方案:以全域场景重构,激活智造新未来
重构
nbsaas-boot3 天前
当前市场环境下,软件行业的突围之道:技术演进与商业模式重构
重构
lingling0093 天前
3D视觉重构工业智造:解码迁移科技如何用“硬核之眼“重塑生产节拍
科技·3d·重构