简体   繁体   中英

Vue.js: how to access the vm object created by vm-router?

I have started a vue instance with vue-router.

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App'

Vue.use(VueRouter);

let router = new VueRouter();

router.start(App, 'body');

As we created a vm component with new phrase, we can get:

var app = new App({
    data: {
        a: 1,
        b: 2
    }
});

So in my router case, how can I access the vm object?

See the documentation of vue-router : http://vuejs.github.io/vue-router/en/api/properties.html

We can just get the property: router.app to get the vm instance.

Vue.use(VueRouter);

let router = new VueRouter();

router.start(App, 'body');

let app = router.app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM