François Romain
François Romain

Reputation: 14393

Bootstraping with vue 2, router and vue-loader

With vuejs 1 the code was:

const App = Vue.extend(Index);
router.start(App, '#app');

Where Index is a component.

I try to convert it to vue 2 like this:

const App = Vue.extend(Index);
const app = new App(router).$mount('#app');

But this gives an [Vue warn]: Error when rendering root instance.

What is the correct way to re-write this?

thanks

Upvotes: 1

Views: 1325

Answers (2)

Atinux
Atinux

Reputation: 1703

You have to give the router as a parameter:

const app = new App({ router }).$mount('#app');

Example:

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>

Upvotes: 4

Samuell
Samuell

Reputation: 45

Try this (App == Index)

const App = Vue.extend(require('./App.vue'))

const router = new VueRouter({
  routes,
  mode: 'abstract'
})

new App({
  router,
}).$mount('#app')

Upvotes: 2

Related Questions