重构项目 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>
     否则会报如下警告
相关推荐
net3m3319 小时前
C#插件化架构(Plugin Architecture)或 可插拔架构,根据产品类型编码的不同自动路由到目标函数,而无需为每个产品都编码相应的代码!!
重构·c#
福客AI智能客服20 小时前
电商智能客服机器人:AI客服聊天系统如何重构用户沟通方式
人工智能·重构·机器人
ai产品老杨20 小时前
协议破壁与流媒体重构:基于 GB28181/RTSP 的企业级视频统一接入方案
重构·音视频
平凡而伟大(心之所向)1 天前
AI重构制造:2026年工业智能体的实战与进化
人工智能·重构·制造
昨夜见军贴06161 天前
AI报告文档审核赋能数据不出域:IACheck重构机械制造行业本地化质量管控体系
大数据·人工智能·重构
Datacarts2 天前
AI大模型时代:微店商品数据API如何重构反向海淘决策
大数据·人工智能·重构
2601_949925182 天前
空运舱位突发爆舱?解析 AI Agent 如何在 2 小时内重构物流应急响应底层逻辑
人工智能·重构·物流rpa
AI先驱体验官2 天前
AI智能体赛道新机遇:2026机会与挑战深度解析
大数据·人工智能·深度学习·重构·aigc
TOSUN同星2 天前
研发周期缩短、成本压力大?同星云平台用“数字孪生+AI”重构研发模式
人工智能·重构