Vue路由器。Root Vue没有数据?

bbs*_*nbb 7 vue.js vue-router

我正在努力使Vue-Router成为现实。我习惯像这样实例化Vue ...

vm = new Vue({
   el : '#vueRoot',
   data : { msg : 'hello' }
   ...
})
Run Code Online (Sandbox Code Playgroud)

现在,我被要求通过路由器实例化它...

vm = new Vue({
   router  
}).$mount('#vueRoot');
Run Code Online (Sandbox Code Playgroud)

我的问题是,我应该将我的datamethods或其他我通常会使用的其他Vue属性放在哪里?我看到我的根Vue可以带有router-link元素的标记。我是否了解,一旦使用路由器,一切都应该放在组件中吗?

Tho*_*mas 6

您可以使用默认符号:

new Vue({
  el: '#app',
  router,
  template: '<MyApp/>',
  components: { MyApp }
})
Run Code Online (Sandbox Code Playgroud)

但是<router-view/>,您的模板中必须包含一个Element。