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>

 

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