So I'm trying to wrap my head around how to use the vue-loader for Webpack, vue-router for routes, and how to have a shared data model. My understanding is that you create a data model, and then pass it into each component with the idea that they have a shared state. It also seems that you should use the data model rather than props, as that allows for two-way binding.
I've tried a few things but nothing seems to work. I tried passing the data through in the router, but that doesn't fix it.
I have this as my main app.js:
var $ = require('jquery'),
Vue = require('vue'),
VueRouter = require('vue-router');
Vue.use(VueRouter);
var first = require('vue!./first.vue');
var second = require('vue!./second.vue');
var sourceOfTruth = {
msg: "my message"
};
var App = new Vue({
data: sourceOfTruth,
});
var router = new VueRouter({
history: true
});
router.map({
'/foo': {
data: sourceOfTruth,
component: first
},
'/bar': {
data: sourceOfTruth,
component: second
}
});
router.start(App, '#app');
And this as my first.vue:
<template>
The message goes here -> {{ msg }}
</template>
<script type="text/javascript">
// ???
</script>
Any ideas? Thanks!
require('vue!./second.vue');Mind to explain what it does? I mean the part before the dot.vue-loader.