
報錯!!!
報錯關鍵詞: 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'
})
}
}
}
然后就完美解決了
公告
浙公網安備 33010602011771號