总结使用vue3开发遇到的问题

总结一下利用Vue3开发组件时跟着视频做还是碰到的各种奇怪的问题

  • 1--- 父组件引用子组件时浏览器控制台出现如下警告,并且组件内容没有正常渲染出来

[Vue warn]: Invalid VNode type: true (boolean)
 at <Home onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
 at <RouterView>
 at <App>

在vue3中要引入defineAsyncComponent才能加载异步组件。

写法如下:

import { defineAsyncComponent } from 'vue'

export default {

    name: 'Home',

    components:{

       'a-button':defineAsyncComponent(()=>import('@/components/button'))
    }

}
  • 2--- 引入element-ui报错

 main.js文件中是这样写的

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

createApp(App).use(router).use(ElementUI).mount('#app')

原因是:目前element-ui只支持2.6以下的版本,Vue3要使用element-ui就要使用element-plus

1.安装element-plus: npm install element-plus --save

2.在main.js中注册element-plus

注意与Vue2的注册有些不一样,先创建app 在用 use

main.js文件内容修改为: 

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus  from 'element-plus'
import 'element-plus/dist/index.css'

createApp(App).use(router).use(ElementPlus).mount('#app')
  • 3--- 使用elementUI的插槽时显示为空白

使用 <template slot-scope="scope"> 时想要的内容就不显示了,为空白

在vue3.0中,插槽的使用方式已经改变了,所以是渲染不出来的。

注意:vue3使用 v-slot 代替了 slot;只能在template标签上使用 v-slot

elementUI中  slot-scope="scope"  的写法在vue3中变成如下

//匿名插槽格式
<template v-slot="scope">
	<slot :name="item.slot_name"></slot>
</template>


//具名插槽格式
<template v-slot:name="name">

//简略写法
<template v-slot:name>

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值