重构项目 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>
     否则会报如下警告
相关推荐
深圳恒讯12 小时前
维度重构:全球直播 vs 纯海外直播的云服务硬核配置
大数据·重构
一 铭20 小时前
Pi实战 10:重构与避坑篇——让 Pi 重构大项目而不搞砸
重构
sxgzzn1 天前
如何利用电缆故障定位在线监测系统提升供电安全?
运维·重构·无人机·开关柜局放在线监测·gis局放在线监测
RICE研究笔记1 天前
基于时间戳机制的 OFDM 雷达感知:从回波重构到 USRP B210 无同步符号自回环
重构
云和数据.ChenGuang2 天前
用 Claude Code 重构遗留系统:从评估到落地的完整指南
java·人工智能·spring boot·后端·重构·springai
rannn_1112 天前
用 Claude Code 重构遗留系统:从评估到落地的完整实践指南
重构
wuyk5552 天前
样章-第10讲-看门狗异常恢复与卡机排查方法论
stm32·单片机·嵌入式硬件·重构
YH行业报告分析2 天前
2026费用管理软件工具市场洞察:AI Agent与RaaS模式如何重构企业费控流程?
人工智能·重构
尘中远3 天前
QWT 3D 模块重构记:旧渲染管线改进介绍及实时瀑布图示例
3d·重构
loulanyue_3 天前
构建实时沉浸式世界模型体验:AI+IP与商业模式重构——读Reactor首席技术官Bryce 2026云栖专场演讲
人工智能·重构