重构项目 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>
     否则会报如下警告
相关推荐
电商软件开发 小银19 小时前
从云联惠覆灭到泊位数智崛起:商业模式的合规重构
重构·创业·商业哲学·云联惠·伯位数智·消费返利·老板思维
ayingmeizi16319 小时前
重构增长:生成式AI如何将CRM打造为企业的销售大脑
人工智能·重构
ManageEngineITSM21 小时前
重构可见性:IT资产管理的下一次觉醒
大数据·人工智能·重构·自动化·itsm·工单系统
ManageEngineITSM1 天前
技术的秩序:IT资产与配置管理的现代重构
大数据·运维·数据库·重构·工单系统
浮生了大白1 天前
AI 赋能科研实践:从选题到发表的技术重构之路
人工智能·重构
A_SKYLINE2 天前
低空无人机“一网统飞”深度解构:从技术内核到产业落地,重构低空经济操作系统
人工智能·重构·无人机·产品经理·低空经济
老猿讲编程2 天前
电动化筑基:智能社会的能源革命与产业重构
重构·能源
来让爷抱一个3 天前
2025年企业智慧大脑升级指南:PandaWiki如何用AI重构知识生产力
人工智能·重构
wwlsm_zql5 天前
京津冀工业智能体赋能:重构产业链升级新篇章
人工智能·重构
升鲜宝供应链及收银系统源代码服务5 天前
升鲜宝供应链管理系统-生鲜配送系统_分拣端界面重构设计(一)
spring boot·重构·开源·收银系统·生鲜门店·升鲜宝多门店收银系统