Thank You For Your Time!
我想将接口都模块化出来
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);
})
}
报错说this没有定义。我不知道在car.js中,this指向的是什么?也许是vue-resource?
Thanks for your help!
在vue的方法里面,调用this.$http,this是指向vue组件的。在vue方法里面调用了不是vue组件内部的方法,this是不能指向到vue组件本身的。有几种思路:
car.js改写成这样
getCarList方法放置到vue组件内部的method里面去
以上两种方法