重构项目 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>
     否则会报如下警告
相关推荐
seabirdssss2 天前
重构测试项目为spring+springMVC+Mybatis框架
java·spring·重构·mvc·mybatis
莫叫石榴姐4 天前
DeepSeek驱动下的数据仓库范式转移:技术解耦、认知重构与治理演进
大数据·数据仓库·人工智能·重构·数据分析·deep learning
朝阳395 天前
前端【技术方案】重构项目
前端·重构
AWS官方合作商9 天前
ERP上云新范式:如何重构企业数字化基座
java·数据库·重构·erp
大模型服务器厂商9 天前
大模型知识蒸馏:技术突破与应用范式重构——从DeepSeek创新看AI基础设施演进路径
人工智能·重构
人类群星闪耀时9 天前
重构数据洪流:大数据架构设计的三个关键性转折
大数据·重构
海绵波波1079 天前
Langchain对管道操作符|的重构实现链式流程
python·重构·langchain
AWS官方合作商9 天前
《哪吒2》背后的云端造梦术:如何重构动画电影工业体系
重构
老六哥_AI助理指南9 天前
DeepSeek的开源核爆:当技术民主化重构AI权力版图
人工智能·重构·开源
Robot2519 天前
DeepSeek正重构人形机器人和具身大模型赛道!
大数据·人工智能·科技·重构·机器人·自动驾驶