重构项目 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>
     否则会报如下警告
相关推荐
Amd79410 小时前
Nuxt3 的生命周期和钩子函数(十一)
webpack·生命周期·前端开发·nuxt3·钩子函数·响应修改·渲染过程
Amd7941 天前
Nuxt3 的生命周期和钩子函数(十)
webpack·生命周期·前端开发·nuxt3·钩子函数·编译优化·插件定制
ChristopherKeith1 天前
低代码表单配置平台替代普通表单配置平台,前端部分重构的设计和思路
前端·低代码·重构·vue·平台·表单
金融小白数据分析之路2 天前
python解耦重构,提高程序维护性
开发语言·python·重构
与墨学长2 天前
Rust破界:前端革新与Vite重构的深度透视(上)
开发语言·前端·vue.js·重构·rust·前端框架
Amd7942 天前
Nuxt3 的生命周期和钩子函数(九)
webpack·生命周期·vite·前端开发·nuxt3·钩子函数·编译优化
Amd7944 天前
Nuxt3 的生命周期和钩子函数(八)
typescript·生命周期·nuxt3·钩子函数·数据写入·模式扩展·服务器监听
TiAmo zhang4 天前
C语言实战 | “俄罗斯方块”游戏重构
游戏·重构
Leventure_轩先生4 天前
[DASP]1. 采样与重构
算法·机器学习·重构
Amd7944 天前
Nuxt3 的生命周期和钩子函数(七)
生命周期·nuxt3·错误处理·钩子函数·模块导入·预渲染·构建优化