重构项目 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>
     否则会报如下警告
相关推荐
AI产品测评官2 天前
2025年招聘系统后端重构:为什么我们放弃了传统SaaS,转向了LLM+RPA智能体?
重构·rpa
司铭鸿3 天前
祖先关系的数学重构:从家谱到算法的思维跃迁
开发语言·数据结构·人工智能·算法·重构·c#·哈希算法
Ace_31750887763 天前
微店商品详情接口深度挖掘:从多接口联动到数据全息重构
大数据·python·重构
Tezign_space5 天前
技术破局:人机协作如何重构内容生产流水线,实现成本与效能的范式转移
人工智能·重构·降本增效·人机协作·内容数字化·内容科技·内容+人工智能
数字孪生家族5 天前
视频孪生与空间智能:重构数字时空认知,定义智能决策新范式
人工智能·重构·空间智能·视频孪生与空间智能
科技测评-阿博6 天前
基于企业知识图谱的B2B金融获客模型:从“流量思维”到“数据工程”的重构
金融·重构·知识图谱
qqxhb6 天前
零基础MCP——第5章编程实战基础(网页、数据分析、调试与重构)
重构·数据挖掘·数据分析·多模态·mcp
老蒋新思维7 天前
创客匠人 2025 高峰论谈(11.22-25):AI 智能体重构创始人 IP 打造与知识变现的管理逻辑
大数据·网络·人工智能·网络协议·tcp/ip·重构·知识付费
"YOUDIG"8 天前
AI重构虚拟都市美学:探索GTA风格照片生成网站的创意狂想与技术内核
人工智能·重构
北京阿法龙科技有限公司10 天前
AR眼镜赋能跨国设备运维:打破空间隔阂,重构高效协作|阿法龙XR云平台
运维·重构·ar