重构项目 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>
     否则会报如下警告
相关推荐
村口曹大爷7 小时前
2026年人工智能深度技术报告:架构范式转移、代理化开发生态与算力经济的重构
人工智能·重构·架构
昨夜见军贴061610 小时前
IACheck × AI审核:重构来料证书报告审核体系,夯实生产质量管控第一道防线
人工智能·重构
北京阿法龙科技有限公司14 小时前
AR眼镜+AI:重构工业运维场景的智能核心载体
人工智能·重构·ar
深蓝易网16 小时前
打破数据滞后困局:让MES系统数据实时准确的实操方案
大数据·运维·人工智能·重构·制造
液态不合群19 小时前
【教育数字化】破除“技术空转”困局:低代码如何重构教育系统建设逻辑?
低代码·重构
ayingmeizi16319 小时前
AI赋能·精准增长,工业金属材料企业的AI CRM全链路解决方案
大数据·人工智能·重构·数据可视化·crm
Mendix20 小时前
从 “中国实践” 到 “全球样板”:西门子Mendix 重构跨国工厂数字化新范式
重构·mendix·西门子低代码·it·制造业·创新
渊鱼L20 小时前
ABAQUS二维混凝土细观模型的数字化重建技术(一)几何重构
人工智能·计算机视觉·重构
我送炭你添花20 小时前
Pelco KBD300A 模拟器:TEST02.重构后键盘部分的测试操作一步一步详细指导
python·重构·自动化·计算机外设·运维开发
Loo国昌20 小时前
RAG 第二阶段:数据工程 —— 视觉解析与语义重构
后端·语言模型·重构·prompt