对于 vuejs 1,代码是:
const App = Vue.extend(Index);
router.start(App, '#app');
Index
是一个组件。
我尝试像这样将它转换为 vue 2:
const App = Vue.extend(Index);
const app = new App(router).$mount('#app');
但这给出了一个[Vue warn]: Error when rendering root instance
。
重写这个的正确方法是什么?
谢谢
最佳答案
你必须给路由器作为参数:
const app = new App({ router }).$mount('#app');
例子:
const Index = {
template: `<div id="app">It's working!</div>`
}
const App = Vue.extend(Index)
const router = new VueRouter()
const app = new App({ router }).$mount('#app');
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
<div id="app"></div>
关于vue.js - 使用 vue 2、路由器和 vue-loader 进行引导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39854429/