在项目的根目录新建一个vue.config.js
文件(和package.json同层次目录),然后配置文件如下:
module.exports = {
devServer: {
proxy: {
// 所有的请求起始部分全部用 '/api'代替,比如访问"https://192.168.1.4/movie",那么简写成"/api/movie"即可
'/api': {
target: 'https://192.168.1.4/', //对应自己的接口
changeOrigin: true,
ws: true,
pathRewrite: {
'^/api': ''
}
}
}
}
}
请求数据:
requestData() {
var url = '/api/movie';
this.$http.get(url).then((response) => {
console.log(response);
}, (err) => {
console.log(err);
});
}