重构项目 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>
     否则会报如下警告
相关推荐
da_vinci_x4 小时前
告别“纸片树冠”:SpeedTree 10的次世代 Nanite 植被透射与程序化季相重构工作流
游戏·3d·重构·aigc·材质·技术美术·游戏策划
无代码专家7 小时前
轻流用 AI 无代码重构制造企业产品全生命周期管理
人工智能·重构·制造
热点速递11 小时前
AI招聘重构人才入口:用友大易以大模型驱动全流程智能升级!
大数据·人工智能·重构·业界资讯
2601_9509653711 小时前
破局“数字围城”:在返利浪潮中重构就业主动权
重构·求职·互联网求职·蜂媒返利人才网
福客AI智能客服1 天前
电商店铺效率升级:智能客服系统如何重构服务与转化逻辑
大数据·重构
zach01271 天前
GEO优化的算力贫困悖论:基于数字地缘政治的量子搜索语义重构
人工智能·python·重构
飞Link1 天前
别再被异常数据骗了:深度解析 TSTD 异常检测中的重构模型(AutoEncoder 实战)
人工智能·算法·重构·回归
小猿君1 天前
AGI理想褪色:OpenAI战略转向背后,AI编程范式的重构与博弈
重构·ai编程·agi
呆码科技1 天前
从仓储到配送:商贸物流软件如何重构供应链效率
重构
cskywit1 天前
【MIA2026】用“混合专家”重构 Mamba!Switch-UMamba如何破局2D 图像动态扫描
重构