重构项目 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>
     否则会报如下警告
相关推荐
sali-tec1 天前
C# 基于halcon的视觉工作流-章68 深度学习-对象检测
开发语言·算法·计算机视觉·重构·c#
O***p6041 天前
前端体验的下一次革命:从页面导航到“流式体验”的系统化重构
前端·重构
2501_924794901 天前
企业AI转型为何难?——从“不敢用”到“用得稳”的路径重构
大数据·人工智能·重构
小二李1 天前
第12章 koa框架重构篇 - Koa框架项目重构
java·前端·重构
一水鉴天1 天前
整体设计 定稿 之25 重构和改造现有程序结构 之1 (codebuddy)
开发语言·人工智能·重构
韩曙亮1 天前
【思维模型】第一性原理 ② ( 利用 “ 第一性原理 “ 进行创新 : 归零 -> 解构 -> 重构 | 跨学科学习 )
学习·重构·第一性原理·思维模型·解构·归零
小雨叔2 天前
内容管理趋势:无头CMS+AI,正在重构企业内容运营逻辑
人工智能·重构·内容运营
说私域2 天前
从“搅局”到“重构”:开源AI智能名片多商户商城小程序对电商生态的范式转型研究
人工智能·重构·开源
老蒋新思维2 天前
创客匠人峰会深度解析:知识变现的 “信任 - 效率” 双闭环 —— 从 “单次交易” 到 “终身复购” 的增长密码
大数据·网络·人工智能·tcp/ip·重构·数据挖掘·创客匠人