跨域处理:
在config文件夹的index.js写入:
proxyTable: {
'/apis':{
target:'http://api.nuomeng.langqiyun.cn',
// target:'http://192.168.0.235:8012',
changeOrigin:true,
pathRewrite:{
'^/apis':'/'
}
}
},
import axios from 'axios';
Vue.prototype.$axios=axios;
Vue.prototype.NM = '/apis';
弄了好久,亲测有效: 原文链接
发起一个GET请求
// Make a request for a user with a given ID
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// Optionally the request above could also be done as
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);