Want to take a look at our new docs? Our new docs are now in beta. Have fun!

API: plugins 属性配置

plugins 属性配置

  • 类型: Array
    • 数组元素类型: StringObject

如果数组元素类型是 Object, 其具有以下属性:

  • src: String (文件的路径)
  • ssr: Boolean (默认为 true) 如果值为 false,该文件只会在客户端被打包引入。

plugins 属性使得你可以轻易地为 Nuxt.js 配置使用 Vue.js 插件。

例如 (nuxt.config.js):

module.exports = {
  plugins: ['~plugins/vue-notifications']
}

然后, 我们需要创建 plugins/vue-notifications.js 文件:

import Vue from 'vue'
import VueNotifications from 'vue-notifications'

Vue.use(VueNotifications)

plugins 属性配置的所有插件会在 Nuxt.js 应用初始化之前被加载导入

每次你需要使用 Vue.use() 时,你需要在 plugins/ 目录下创建相应的插件文件,并在 nuxt.config.js 中的 plugins 配置项中配置插件的路径。

想了解更多关于使用插件的信息,请移步 插件使用指引

Contribution for this page is now closed. If you would like to contribute please check out our new docs are now in beta. Have fun!

Platinum Sponsors

StoryblokMoovweb Support Us