vue2.0proxy配置跨域请求配置1
出现这个玩意就是跨域请求了解决办法很多,这里配置'/apis': {// 测试环境target: 'http://www.thenewstep.cn/',// 接口域名changeOrigin: true,//是否跨域pathRewrite: {'^/apis': ''...
·
出现这个玩意就是跨域请求了
解决办法很多,这里配置
'/apis': {
// 测试环境
target: 'http://www.thenewstep.cn/', // 接口域名
changeOrigin: true, //是否跨域
pathRewrite: {
'^/apis': '' //需要rewrite重写的,
}
注意配置好之后项目要重启才能生效
fetch请求
created() {
fetch('/apis/test/xxxx.php', {
//请求方法
method: 'post',
headers: {
//返回给客户端的类型
'Content-type': 'application/json',
//携带tooken
token: "fdggsdflskgg89ssfgss048728dfd59dh"
},
//发送的数据
body: JSON.stringify({username: 'admin', password: '123456'})
})
.then(result => {
return result.json()
})
.then(data => {
console.log(data)
})
}
axios
下载 npm install axios -D
this.$axios.post("/apis/test/xxxx.php",{
username:'hello',
password:'2222'
})
.then(data=>{
//解构赋值
//判断状态码替换数据
})
更多推荐
已为社区贡献9条内容
所有评论(0)