重构项目 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 小时前
登顶 NAVSIM!博世最新IRL-VLA:逆强化学习重构自动驾驶VLA闭环训练
人工智能·重构·自动驾驶
中电金信1 天前
中电金信:AI重构测试体系·智能化时代的软件工程新范式
人工智能·重构·软件工程
通信小呆呆2 天前
5G/6G时代的智能超表面:如何重构无线传播环境?
5g·重构·信息与通信·信号处理·超表面
Android出海2 天前
Google Play账户与App突遭封禁?紧急应对与快速重构上架策略
android·网络·重构·新媒体运营·产品运营·内容运营
字节数据平台2 天前
一客一策:Data Agent 如何重构大模型时代的智能营销
大数据·人工智能·重构
喂完待续2 天前
【序列晋升】28 云原生时代的消息驱动架构 Spring Cloud Stream的未来可能性
spring cloud·微服务·云原生·重构·架构·big data·序列晋升
OkarOu2 天前
5G边缘计算:重构物联网开发新范式
5g·重构·边缘计算
A小弈同学3 天前
新规则,新游戏:AI时代下的战略重构与商业实践
大数据·人工智能·重构·降本增效·电子合同
2zcode3 天前
基于Matlab狭窄空间环境中多无人机自重构V字队形方法研究
重构·无人机
编码浪子3 天前
趣味学RUST基础篇(构建一个命令行程序2重构)
开发语言·重构·rust