在NUXT中如何引用全局组件

在开发过程中,我们经常互封装一些组件,由于组件具有复用性,怎么能够一次引用在所有页面都可以使用呢。

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' 
  ],

大功告成,再也不用每个页面分别引入了

原文地址:https://www.cnblogs.com/yddzyy/p/13269826.html