重构项目 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>
     否则会报如下警告
相关推荐
Promise微笑15 小时前
AI搜索时代的流量重构:GEO优化深度执行细节与把控体系
人工智能·重构
金融小师妹16 小时前
AI政策框架解析:凯文·沃什货币体系重构与美联储治理范式转型
大数据·人工智能·重构·逻辑回归
霍小毛18 小时前
「数智孪生·绿动未来」新能源智慧工地管控平台——重构工程管理新范式
重构
三维频道21 小时前
不止于精度:汽车精密锻铸件质检的“数据降维”与方案重构
3d·重构·汽车·工业数字化·蓝光三维扫描仪·汽车供应链·汽车智能制造
智慧物业老杨1 天前
物业科技化红利落地实战:从工单系统重构到AIOT全链路价值挖掘
重构
南村群童欺我老无力.1 天前
鸿蒙 - Progress进度条从手工拼装到原生组件的重构
华为·重构·harmonyos
EasyDSS1 天前
私有化音视频系统/视频直播点播/高清点播/音视频点播EasyDSS重构智慧校园教学与资源传播新生态
重构·音视频
智象科技1 天前
AI重构IT运维:从被动救火到智能自治,这场革命已不可逆!
大数据·运维·人工智能·ai·重构·一体化运维
RD_daoyi2 天前
谷歌2026年 3 月核心更新深度解析:SEO 从内容优化到信息供给系统的全面重构
人工智能·算法·重构
中电金信2 天前
中电金信:填平信创落地“真空地带”,中试重构行业系统工程能力
重构