1、fetch
App.vue
//跨域请求处理
created(){
//fetch
fetch("/apis/server_new/login",{
method:“post”,
header:{
// “Content-type”:“application/json”,
token:“54cas56156d4a6s1das1d6sa4d6a51d65asd”
},
body:JSON.stringify({username:“admin”,password:“123456”})
})
.then(result=>{
// console.log(result)
return result.json()
})
.then(data=>{
console.log(data)
})
}
在config/index.js
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/apis': { //将www.exaple.com印射为/apis
target: 'https://www.exaple.com', // 接口域名
secure: false, // 如果是https接口,需要配置这个参数
changeOrigin: true, //是否跨域
pathRewrite: {
'^/apis': '' //需要rewrite重写的,
}
}
},
重启:必须重启