D
D
DenniLa22020-05-03 08:29:10
Vue.js
DenniLa2, 2020-05-03 08:29:10

How to get property from plugin in vue component?

The plugin has its own store. There is someProp property in the plugin store.

export default {
  namespaced: true,
  state: {
    someProp: null,
  },
  mutations: {
    set(state, value) {
      state.someProp = value;
    },
  },
}

The plugin is installed in Vue.prototype.$myPlugin

import myStore from './store'

export default {
  install(Vue, { store }) {
    store.registerModule('myStore', myStore);

    Vue.prototype.$myPlugin = {
      set(value) {
        store.commit('myStore/set', value);
      },
      // как правильно возвращать someProp из стора через плагин?
      someProp: store.state.myStore.someProp, // << это возвращает null и после изменения через мутацию
    };
  }
}


I want to do this in the component: Tell me how to do this?
<div>{{ $myPlugin.someProp }}</div>

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