How to use vue plugin in nuxt

There's a plugin called vue-chat-scroll and I would like to use it in 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. how would one do that?

Upvotes: 3

Views: 3544

Answers (2)

Shadi Farzankia
Shadi Farzankia

Reputation: 737

Create a js file in plugin folder and name it vue-chat-scroll.js (the name is optional. It depends on you). then register your plugin inside this js file as follows:

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:

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

Upvotes: 4

Vigikaran
Vigikaran

Reputation: 725

  1. Create a file inside plugins folder, for example, vue-chat-scroll.js with the following content:

    import Vue from 'vue'
    import VueChatScroll from 'vue-chat-scroll'
    Vue.use(VueChatScroll) 
    
  2. In nuxt.config.js import the plugin as

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

and then follow the plugin tutorial for its API

Upvotes: 1

Related Questions