配置vue,config.js
module.exports = {
devServer: {
open: true,
host: 'localhost',
port: 8080,
https: false,
//以上的ip和端口是我们本机的;下面为需要跨域的
proxy: {//配置跨域
'/kua': {
target: 'https://mobile.iwangxing.cn/web/api',//这里后台的地址模拟的;应该填写你们真实的后台接口
ws: true,
changOrigin: true,//允许跨域
pathRewrite: {
'^/kua': ''//请求的时候使用这个api就可以
}
}
}
}
}
挂载到vue对象
Vue.prototype.$http = axios.create({
//baseURL:process.env.VUE_APP_API_UR || '/web/api'
//baseURL:'kua'
})
使用时
async fetch(){
const res = await this.$http.get('kua/heroes/list')
console.log(res);
//this.newsCats = res.data
}