axios请求跨域问题
coconutnut

发现有跨域问题

查到

https://www.cnblogs.com/l-y-h/p/11815452.html

照着改了一下

但是又出现了

1
Cannot set property $http of #<Vue> which has only a getter at eval axios

最后解决方法

vue.config.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://***:3000/',
// 允许跨域
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}

调用

1
2
3
4
5
this.$axios.get('/api/findall').then(response => {
console.log(response.data)
}).catch(function (error) {
alert(error);
});