axios跨域问题

2022/9/14 6:16:17

本文主要是介绍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'
              })
            }
          }

        }

然后就完美解决了



这篇关于axios跨域问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程