Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue router. Root Vue has no data?

I'm trying to get my head round vue-router. I'm used to instantiating Vue like this...

vm = new Vue({
   el : '#vueRoot',
   data : { msg : 'hello' }
   ...
})

Now I'm being asked to instantiate it passing the router...

vm = new Vue({
   router  
}).$mount('#vueRoot');

My question is where do I put my data or methods, or whatever other Vue properties I would normally use? I see that my root Vue can have markup, with router-link elements. Am I to understand that, once I use the router, everything should be in components?

like image 485
bbsimonbb Avatar asked Jan 15 '18 13:01

bbsimonbb


People also ask

Do we have router reload in vue router?

You can force-reload components by adding :key="$route. fullPath". However, :key="$route. fullPath" only can force-reload the components of the different route but not the components of the same route.


1 Answers

You can use your default notation:

new Vue({
  el: '#app',
  router,
  template: '<MyApp/>',
  components: { MyApp }
})

But you must have a <router-view/> Element in your template.

like image 157
Thomas Avatar answered Nov 09 '22 07:11

Thomas