为了解决这个问题,有两种开发思路,一是在引入 axios 之后,修改原型链,二是结合 Vuex,封装一个 aciton。
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
方法一
//mutations.js
const mutations={
getNewlists(state) {
axios({
method: 'get',
url: baseURL+'/social/fangles/findLatest'
}).then(function(res){
console.log(res);
state.schoolNewList=res.data;
})
}
}
//news.vue
this.$store.dispatch('getNewlists')
方法二
Vue.prototype.$ajax = axios
methods: {
getNewlists () {
this.$ajax({
method: 'get',
url: baseURL+'/social/fangles/findLatest',
}).then(function(res){
console.log(res)
})
}
vue2.0-axios is defined
猜你喜欢
转载自my.oschina.net/u/3392853/blog/1624291
今日推荐
周排行