How is vue-resource abstractly used in interfaces?

< H2 > Thank You For Your time! < / H2 >

I want to modularize all the interfaces

index-page.vue

import {
    getCarList
} from "api/car.js";


created: function () {
    getCarList();
},

car.js

export function getCarList() {
    let url = domain + "/api/webOldCar/initNominate.action";
    this.$http.get(url).then((res) => {
        console.log(res);
    })
}

error report that this is not defined. I don"t know what this points to in car.js. Maybe it"s vue-resource?.

< hr >

Thanks for your help!

Mar.30,2021

in the method of vue, the call to this.$http,this points to the vue component. Methods that are not internal to the vue component are called in the vue method, and the this cannot point to the vue component itself. There are several ideas:

car.js is rewritten like this

import axios from 'axios'

export function getCarList() {
    let url = domain + '/api/webOldCar/initNominate.action';
    axios.get(url).then((res) => {
        console.log(res);
    })
}
The

getCarList method is placed in the method inside the vue component

import {
    getCarList
} from 'api/car.js';


created: function () {
    this.getCarList();
},
methods: {
    getCarList: getCarList
}

the above two methods

Menu