重构项目 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>
     否则会报如下警告
相关推荐
文火冰糖的硅基工坊10 小时前
《投资-113》价值投资者的认知升级与交易规则重构 - 复利故事终止的前兆
重构·架构·投资
文火冰糖的硅基工坊14 小时前
[嵌入式系统-101]:AIoT(人工智能物联网)开发板
人工智能·物联网·重构·架构
hqyjzsb17 小时前
2025 年项目管理转型白皮书:AI 驱动下的能力重构与跨域突破
开发语言·人工智能·重构·产品经理·编程语言·caie
萤丰信息17 小时前
从超级大脑到智能毛细血管:四大技术重构智慧园区生态版图
java·人工智能·科技·重构·架构·智慧园区
科技峰行者17 小时前
Sora2:AIGC的技术革命与生态重构
重构·aigc
棱镜研途17 小时前
科研快报 |声波“听”见火灾温度:混合深度学习重构三维温度场
人工智能·深度学习·目标检测·重构·传感·声波测温·火灾安全
zandy10111 天前
衡石科技嵌入式BI:重构企业应用的数据智能生态
科技·重构·bi·嵌入式bi
Spring_java_gg1 天前
未来 3 年,编程语言将被大模型重构?
重构
weixin_549808361 天前
从效能革命到体验重构,易路 AI Agent 破局 HR 三重困境
大数据·人工智能·重构
disanleya1 天前
MySQL时间格式转换,时间数据混乱不堪如何彻底重构?
数据库·mysql·重构