当前位置: 首页 > news >正文

重构项目 vue2 => vue3 nuxt2 => nuxt3 遇到的问题

  1. vue3获取组件的上下文

    import { getCurrentInstance } from 'vue';
    // 获取当前组件实例
    const instance = getCurrentInstance();
     
    // 获取当前组件的上下文,下面两种方式都能获取到组件的上下文。
     //  方式一,这种方式只能在开发环境下使用,生产环境下的ctx将访问不到
    const { ctx }  = getCurrentInstance(); 
    //  方式二,此方法在开发环境以及生产环境下都能放到组件上下文对象(推荐)
    const { proxy }  = getCurrentInstance();  
    
  2. nuxt3 中使用Vue <component :is="someComputedComponent">语法,需要使用Vue提供的resolveComponent辅助方法,否则无法正常渲染组件,且组件名称必须是字符串而不是变量

    <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"来创建一个浅响应式对象。

    const componentMap = markRaw(myComponent)
  4. elementPlus与elementUI语法升级 

    //elementUI的descriptions组件插槽语法:
    <el-descriptions>
        <template slot="extra"></template>
    </el-descriptions>
    //elementUI的elementPlus组件语法:
    <el-descriptions>
        <template #extra></template>
    </el-descriptions>
    否则会不展示插槽内容
    //elementUI的popover组件插槽语法:
     <el-popover>
         <div  slot="reference"></div>
     </el-popover>
     //elementUI的popover组件语法:
      <el-popover>
         <template #reference></template>
     </el-popover>
     否则会报如下警告

 

相关文章:

  • 【linux进程(三)】进程有哪些状态?--Linux下常见的三种进程状态
  • 远程实时监控管理:5G物联网技术助力配电站管理
  • 百度将在世界大会上发布AI大模型文心4.0;OpenAI考虑自主开发AI芯片
  • Java中使用正则表达式
  • CSS3实现动画加载效果
  • nginx-proxy反向代理缓存
  • Unity可视化Shader工具ASE介绍——3、ASE的Shader类型介绍
  • ds套dp——考虑位置转移or值域转移:CF1762F
  • Flink--9、双流联结(窗口联结、间隔联结)
  • 读书笔记--未来简史关键金句和阅读感悟
  • 「专题速递」JPEG AI、端到端图像编码的标准化及产品落地、深度学习
  • Angular学习笔记:路由
  • 攻防世界-fakebook
  • Python 无废话-办公自动化Excel修改数据
  • 【高性能计算】CUDA编程之OpenCV的应用(教程与代码-4)//test error
  • kubectl系列(六)-kubectl describe
  • ArcMap:第二届全国大学生GIS技能大赛(广西师范学院)详解-上午题
  • 阶段六-Day01-Linux入门
  • 【12】c++设计模式——>单例模式练习(任务队列)
  • Charles:移动端抓包 / windows客户端 iOS手机 / 手机访问PC本地项目做调试
  • 政策一视同仁引导绿色转型,企业战略回应整齐划一?
  • 王毅同巴基斯坦副总理兼外长达尔通电话
  • 广西钦州:坚决拥护自治区党委对钟恒钦进行审查调查的决定
  • 中方就乌克兰危机提出新倡议?外交部:中方立场没有变化
  • 九家企业与上海静安集中签约,投资额超10亿元
  • 视频丨习近平同普京会谈:共同弘扬正确二战史观,维护联合国权威和地位