axios跨域问题
作者:互联网
报错!!!
报错关键词: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.
接口不正确Access-Control-Allow-Headers不允许请求报头字段内容类型。
需要添加
"https://www.imooc.com/api/http/json/search/suggest?word=js",
login_password(){
if (this.username && this.password) {
//发送请求
this.$axios.post(this.$settings.base_url + '/user/login/', "https://www.imooc.com/api/http/json/search/suggest?word=js", {
username: this.username,
password: this.password,
}).then(response => {
console.log(response.data)
//把用户信息保存到cookie中
// this.$cookies.set('key','value','过期时间,按s计')
this.$cookies.set('token',response.data.token,'7d')
this.$cookies.set('username',response.data.username,'7d')
//关闭登录窗口(子传父)
this.$emit('close')
//给父组件,Head传递一个事件,让它从cookie中取出token和username
}).catch(errors => {
console.log()
})
}else{
this.$message({
message:'不行,用户名和密码必须填哦',
type:'warning'
})
}
}
}
然后就完美解决了
标签:username,cookies,axios,跨域,问题,token,set,password,response 来源: https://www.cnblogs.com/xionghuan01/p/16691596.html