No idea. As weāre already giving some examples, hereās something you may want to have implemented in the future. The way to synchronize Vue-router with Vuex store, so that recent router data is available for you as Vuex submodule:
import { Meteor } from 'meteor/meteor'
import { Vue } from 'meteor/akryum:vue'
import Vuex from 'vuex'
import Router from 'vue-router'
import { sync } from 'vuex-router-sync'
import VuexStore from '/imports/vuex/store'
import { routes } from '/imports/routes/main'
import App from '/imports/ui/App.vue'
Vue.use(Router)
const store = new Vuex.Store(VuexStore)
const router = new Router({
routes,
mode: 'history',
})
sync(store, router)
Meteor.startup(() => {
new Vue({
router,
store,
render: h => h(App),
}).$mount('app')
})
Lol. That was completely by chance. I just followed the code in some tutorial and didnāt even notice that it is not the akryum:vue-router2 Iām importing. Anyways, it works fine.
The difference most possibly is that Iām now not able to write my routes in /client folder, as it is described in akryum:vue-router docs and forced to do them all in /imports. That was a nice feature that I saw in example apps but couldnāt implement in my code for some reason and it makes sense now that you pointed it out.
Vue.use(plugin) installs plugins into vue. You need to install the plugins before starting the Vue apps/widgets, otherwise the modifications made by the plugins wonāt be applied to the already created Vue instances.
Yeah I think an article on Meteorās Medium blog would be a great place to start. That could put Meteor + Vue on the map in a bigger way, and then more people will try it to figure out best practices! The post can just list some of the different ways to get started.
@aadams you can easily make that using the way I introduced in Vuex+Accounts example + possibly get() and set() for computed variable that I wrote an example for earlier, you can also find that part in the Vuex docs.
But trying to put every little bit of the state into Vuex will end up being more boilerplate than itās worth.
Thanks for the advice @akryum & @gusto. Can we turn the question around, under what circumstances should we use vuex?
``> I need to pass state between ātemplatesā (at a higher āpageā level). Like the template level of Blaze, and the state would be pass around like what I used to use Session for ā and ID or the like.
`` > I need to pass data between components (I can use and empty Vue instance for this). So what I would use ReactiveVars for before.
`` > I need to retrieve many documents from Mongo, and perform many calculations on fields, and then store this information for consumption by the lager ātemplatesā. There is a lot of data in one Session I pass around to some of the templates. This to me is what I think makes the most sense for using vuex.
So if Iām going to need to use for that large dataset, why not learn how to use it now? Maybe I donāt store client side validation variables inside it, but eventually Iām going to need it.
Oh-well, Iāll try simple form control validation with a shared Vue instance and pick up vuex later.
@akryum, Iām wondering, are you instantiating a new Vue instance for each <component-name>.vue file, and tying the name of that instance to the file name (unless a name property is specified inside the control) with the vue-component lib?
If so, then are you binding the <script>data</script> attribute within the <component-name>.vue file to said new Vue instance?
If you mean Vue component definition, then yes. If you donāt define a name, akryum:vue-component will do it for you based on the filename. Plus, if you put your Vue files outside of imports, it will register them automatically with Vue.component().
Itās just, please correct me, but when reviewing the Guide and API, it seems that each component is actually a new Vue instance, and these instances communicate via events, such as v-model, $emit, and $on. And the data attribute binds to the markup. But itās all centered about the new Vue instance.
But when building these component .vue files, Iām not making new Vue instances each time, just the one in my app.js file like so:
Meteor.startup(() => {
const app = new Vue({
router: router,
render: h => h(AppLayout),
}).$mount('app');
});
So I was wondering if you were actually doing this for us under the covers so to speak.