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>