重构项目 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>
     否则会报如下警告
相关推荐
金融RPA机器人丨实在智能4 小时前
2026动态规划新风向:实在智能Agent如何以自适应逻辑重构企业效率?
算法·ai·重构·动态规划
Kiyra10 小时前
从《守望先锋》2026前瞻,看大型分布式系统的“重构”与“并发挑战”
运维·服务器·重构
Niuguangshuo14 小时前
DALL-E 3:如何通过重构“文本描述“革新图像生成
人工智能·深度学习·计算机视觉·stable diffusion·重构·transformer
天天进步201514 小时前
Motia性能进阶与未来:从现有源码推测 Rust 重构之路
开发语言·重构·rust
TMT星球14 小时前
云从科技AI智能体落地中冶京城,重构工程领域数字化辅助新范式
人工智能·科技·重构
Allen_LVyingbo14 小时前
医疗AI新范式:当数理模型开始“计算”生命,传统大模型面临重构(中)
开发语言·人工智能·python·自然语言处理·重构·知识图谱
人机与认知实验室1 天前
人机协同:主体性的转移与重构
重构
科技圈快讯1 天前
智能体工厂引领工业跃迁:美云智数全域AI重构研产供销价值链
人工智能·重构
Promise微笑2 天前
信任重构与AI采信:深度解析“两大核心+四轮驱动”Geo优化新范式
人工智能·重构
百***35482 天前
2026年AI搜索时代的企业认知突围:微盟星启如何重构品牌信息基础设施
人工智能·重构