Vuex External File
Setup Vuex with external file https://vuex.vuejs.org/installation.html
But after this make a file in the resources/assets/js
called store.js
then set it up as needed
Here I will have one loading state
export default {
state: {
loading: true,
},
getters: {
loading: state => {
return state.loading;
},
},
mutations: {
loading(state, loading) {
state.loading = loading;
}
}
};
now import it into your app.js
import store from './store';
and
var app = new Vue({
mixins: [require('spark')],
store: new Vuex.Store(store),
router
});
That should do it. I do load some state in my resources/views/layouts/app.blade.php
<script>
window.Laravel = {!! json_encode([
"apiToken" => auth()->user()->api_token ?? null
]) !!};
</script>
Just to help with some basic stuff
comments powered by Disqus