How does vue-resource return get the value?

Boss, let me ask you a question. I am working on a workbench project that requires all data requests to be managed in a js file. I now execute the request data method here, and then I can"t get the value of return. Please help me to see what"s going on. Thank you!

import Vue from "vue"
import VueResource from "vue-resource"
Vue.use(VueResource);
import store from "@/vuex.js";
var datap={
    get:{
        header(){
            var url="static/data/header.json"
            Vue.http.get(url).then((response)=>{
                 var data=JSON.parse(response.bodyText);
                 store.state.homeNav=data.nav;
                store.state.headerUserInfo=data.userInfo;
                store.state.headerMessage=data.message;
                **return data;**        //        
            },error=>{
                //console.log(err);
                //return error.json();
            }).then(result => {
                //console.log(result);
            })
        }
    },
    post:{
        
    }    
}
export {datap};
Jun.30,2021

there is no callback for this method, only then to get the returned value:

var test=Vue.http.get(url).then((response)=>{
    ----------
    //return data;       //return
    return Promise.resolve(data) // Promise
},error=>{
    //console.log(err);
    //return error.json();
}).then(result => {
    //resultPromise.resolve(data)
    //console.log(result);
})

you can see here that you are not familiar with the chained writing of then . It is recommended that you take a look at ES6 new syntax Promise , and try not to use the original callback hell

.
Menu