首先在webpack.config.js中增加proxy内容,设置代理。
... devServer: { host : '192.168.3.100', port: 3000, proxy : { '/ajax/*': { //只要指向/ajax/的请求,都会自动代理到下面的target的地址 target: 'http://192.168.3.100', //对方服务器地址 secure: false } } } ...01.
02.
03.
04.
05.
06.
07.
08.
09.
10.
11.
12.
接着我们在请求ajax的时候,一定要请求当前服务器的路径,并不是请求对方服务器的路径。比如:
//这里请求自己服务器,如果自己服务器有端口号,同样要加上端口号 this.$http.get('http://192.168.3.100:3000/ajax/getNews.php').then(function(n){ console.log(n.data) })01.
02.
03.
04.