简体   繁体   中英

How to use vue-resource with a vue-router instance?

Before I installed my router I set up a global Vue instance and used vue-resource like this:

export const befriend = (recipient, event) => {
    Vue.http.post('/route',{
        // Data
    }).then(function(response) {
        // Success
    }.bind(this), function(response) {
        // Error
    });
}

Now my Vue instance is being instantiated by the router itself like this:

router.start(App, 'body');

How can I use vue-resource when I have no variable bound to my instance?

Nevermind I found the answer in the vue-router documentation hidden at the bottom of the page.

In addition:

The root Vue instance will be available as router.app once the initial render is complete.

The router instance will be available in all descendants of the router app as this.$router.

Hope this is of use for someone else who didn't read every bit of the docu mentation.

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