config>index.js
proxyTable: {
'/api': {
target: 'http://bfr.n13.com.cn',// 请换成你的地址
changeOrigin: true,
pathRewrite: {
'^/api': '/api'
}
}
}
main.js
const host = process.env.NODE_ENV === "development" ? "" : "http://bfr.n13.com.cn";
const instance = axios.create({
baseURL: host
})
Vue.prototype.axios = instance;
index.vue
this.axios.get('/api/gettopimg.aspx')
.then(res => {
console.log( res.data)
})
然后在服务器端把getClass.aspx的请求文件放在一个api的文件夹里面,这样开发的时候不需要服务器设置跨域了,生产的时候,服务器端设置一下允许跨域就好了,用cors跨域。