简体   繁体   English

如何在nuxt中使用vue插件

[英]How to use vue plugin in nuxt

There's a plugin called vue-chat-scroll and I would like to use it in nuxt.有一个叫做 vue-chat-scroll 的插件,我想在 nuxt 中使用它。 Am a beginner so I cant really understand how but I wonder if its possible to use this vue plugin in nuxt as plugin.我是初学者,所以我无法真正理解如何,但我想知道是否可以在 nuxt 中使用这个 vue 插件作为插件。 how would one do that?怎么做呢?

  1. Create a file inside plugins folder, for example, vue-chat-scroll.js with the following content:在 plugins 文件夹中创建一个文件,例如 vue-chat-scroll.js,内容如下:

     import Vue from 'vue' import VueChatScroll from 'vue-chat-scroll' Vue.use(VueChatScroll)
  2. In nuxt.config.js import the plugin as在 nuxt.config.js 中将插件导入为

     plugins: [...your existing plugins,'~/plugins/vue-chat-scroll.js']

and then follow the plugin tutorial for its API然后按照其 API 的插件教程进行操作

Create a js file in plugin folder and name it vue-chat-scroll.js (the name is optional. It depends on you).在 plugin 文件夹中创建一个 js 文件并将其命名为 vue-chat-scroll.js (名称是可选的。这取决于您)。 then register your plugin inside this js file as follows:然后在这个 js 文件中注册你的插件,如下所示:

import Vue from 'vue';
import VueChatScroll from 'vue-chat-scroll';

 Vue.component('VueChatScroll', VueChatScroll);

Then import it in nuxt.config.js inside plugins as follow:然后将其导入插件内的 nuxt.config.js 中,如下所示:

plugins: [
  {
    src: '~/plugins/vue-chat-scroll.js',
    ssr: true
   }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM