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

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

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

相关文章:

  • 2022-12-23
  • 2021-10-15
  • 2023-01-15
  • 2021-05-06
  • 2022-12-23
  • 2021-11-25
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2022-02-05
  • 2023-01-13
  • 2023-01-13
相关资源
相似解决方案