【在点击登陆的时候,遇到了好多不懂得东西,比如说接口的问题,还不是很能理解关于接口 _Ajax 】 | IT修真院·坑乎
问题已收录 在点击登陆的时候,遇到了好多不懂得东西,比如说接口的问题,还不是很能理解关于接口
我也踩过这个坑( 1 )
已统计您的踩坑,无需重复点击
回答(1)
Ajax
详细描述
截图
代码
编辑于2024-05-06
  • [上海|荣耀师兄]JS-左昌杰
    0

    安装axios


    在main.js 里初始化$http

    import axios from "axios";

    Vue.prototype.$http=axios;


    this.$http({

                method: "POST", //定义POST请求

                url: "/carrots-admin-ajax/a/login", //请求地址    

                params: { //params可以把$scope的对象序列化成键值对形式

                  name: this.user,

                  pwd: this.password,

                }


              }).then(response => { //发起请求成功


                console.log(response);

                // console.log(response.data)

                // console.log(response.data.code)

                if (response.data.code == "-5003") {

                  this.hint = response.data.message; //提示用户名错误

                } else if (response.data.code == "-5004") {

                  this.hint = response.data.message; //提示密码错误

                } else if (response.data.code == "0") {

                  // console.log(response.data.code)

                  this.hint = "登录成功"; //提示登录成功

                   let username = response.data.data.manager.name;

                  // console.log(username);

                  localStorage.setItem("username", JSON.stringify(username));

                  // this.$router.push({ path: "/Home"});

                }

              }, function (response) { //发起请求失败

                // console.log(response);

                location.href = "404"; //跳转到404

              })


    编辑于2019-01-25