[Vuejs]-How to call vuex from a laravel blade file

0๐Ÿ‘

 var app = new Vue({
    el: '#app',
    store: store,
    data: {
    },
    methods: {
     changeVillageMethod() {
       var cval = 'somevalue';
       this.$store.commit('changeVillage', cval)
     },
    },
    computed: {
      village() {
         return this.$store.state.village;
      },
    },
});

Now you have access to village value and changeVillageMethod method in the template part.
I recommend reading Veux docs. https://vuex.vuejs.org/

0๐Ÿ‘

try again according to the instructions:

import Vuex in the file bootstrap.js:

import Vuex from 'vuex';
...
window.Vuex = Vuex;
Vue.use(Vuex);

then make the following changes to the file app.js:

import store from './YOUR_FILE_WITH_DEFINITION_STORAGE_VARIABLE.js';
new Vue({
  el: '#app',
  store: new Vuex.Store(store)
});

and your storage JS file:

let store = {
...
};
export default store;

Leave a comment