M
M
mShpakov2018-06-09 13:43:18
Vue.js
mShpakov, 2018-06-09 13:43:18

Nuxtjs how to call a plugin inside a plugin?

Connected the vue-notification plugin to ~plugins/vue-notification.js

import Vue from 'vue';
import VueNotifications from 'vue-notification';

Vue.use(VueNotifications);

And accordingly poked it into nuxt.config.js
plugins: [
    {
      src: '~/plugins/vue-notifications',
      ssr: false
    }
]

If it is called inside a page
this.$notify({
          group: 'alerts',
          title: 'Important message',
          text: 'Hello user! This is a notification!'
        });

That's all ok.
However, when I connect another plugin and try to call this.$notify inside it, I get undefined
export default ({ app }, inject) => {
  const displayAlert = (meta) => {
    // часть кода делающая что-то важно опущена
   this.$notify({
          group: 'alerts',
          title: 'Important message',
          text: 'Hello user! This is a notification!'
        });
    //так же пытался app.$notify. Результат тот же
  };
  inject('displayAlert', displayAlert);
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question