在開發過程中,我們經常互封裝一些組件,由於組件具有復用性,怎么能夠一次引用在所有頁面都可以使用呢。
1、首先封裝組件(mycomponent.vue)
2、在plugins文件夾下建一個文件,my-components.js(名字可以任意起)
內容如下
import Vue from 'vue' import mycomponent from '@/components/mycomponent.vue' Vue.component('mycomponent',mycomponent)
3、在根目錄的nuxt.config.js中,引入做成的js文件
plugins: [ '@/plugins/my-componentr' ],
大功告成,再也不用每個頁面分別引入了