重构项目 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>
     否则会报如下警告
相关推荐
科技新资讯16 小时前
AIGC重构工业设计 一号设计解锁智造新势能
人工智能·重构·aigc
FII工业富联科技服务1 天前
AI如何重构下一代智能工厂:从数字孪生到Factory Agent Brain的技术演进
大数据·人工智能·重构
woshihuanglaoshi1 天前
鸿蒙老旧项目升级改造高级:API废弃迁移/ArkTS语法升级/架构重构策略/增量迁移/风险管控方案
学习·华为·重构·架构·harmonyos·鸿蒙
科技园长2 天前
复杂厂区车辆高精度调配:UWB追踪技术底座与选型格局重构
运维·重构
沐梯子2 天前
2026工业软件数据解析:核心供应链重构下的集成平台选型逻辑
microsoft·重构
九硕智慧建筑一体化厂家2 天前
从光伏板到护眼灯,直流照明如何重构绿色校园的能源基因
运维·人工智能·重构·智慧城市·能源
Clipp_Huang3 天前
光学跟踪系统标定
人工智能·计算机视觉·重构·机器视觉
文艺理科生Owen3 天前
3 年,8 种方案,1 次重构:LangChain 记忆方案如何从混乱走向清晰
重构·langchain
Wang's Blog3 天前
AI Agent白手起家47: 检索器高级应用 — 查询重写与查询重构实战
人工智能·重构