vue全局组件的引入

1,创建组件

在自定义组件的文件夹下(layout)创建组件,并创建index.js文件,

2,导出组件

在index.js内导出组件(可以同时注册多个组件),代码如下:

import QRcode from '@/components/layout/QRcode.vue'
const components={
	install(Vue){
		Vue.component('v-qrcode',QRcode)
  }
}
//判断
if(typeof window !=='undefined' && window.Vue){
	install(window.Vue);
}

export default components;

3,引入组件

在main.js内引入组件库并使用


//引入封装通用组件库
import comUi from "./components/layout/index.js";
//使用组件
Vue.use(comUi);

4,调用组件

 <!--引用生成二维码组件-->
 <v-qrcode :qrcodeList="qrcodeList" :type="codeType" ref="qrcode"></v-qrcode>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章