vue中axios的post和get请求示例

POST请求

 methods: {
    isclick() {
      if (this.account == "" || this.pwd == "") {
        this.$message.warning("请输入账号或密码");
      } else if (this.account && this.pwd) {
        let data = { account: this.account, password: this.pwd };
        this.$axios
          .post("/user/login/", data)
          .then(res => {
            if (res.data.status == 200) {
              this.$message.success(res.data.message);
              this.sendKey.userccount = res.data.account;
              this.sendKey.usertoken = res.data.token;
              //         登录成功产生token放到store
              this.$store.commit("$_setStorage", res.data.token);

              this.$store.commit("$_setAccount", res.data.account);

              this.$router.push({ path: "/home" });
            } else if (res.data.status == 404) {
              this.$message.error(res.data.message);
            } else if (res.data.status == 400) {
              this.$message.error(res.data.message);
            }
          })
          .catch(err => {
            this.$message.error(err.message);
          });
      }
    }
  }

  

GET请求

    get_allcase() {
      // 所有的case
      // let all_type = "1";
      let data = {
        casetype: "1",
        modular_type: "0",
        case_name_type: "0",
        pagenum: 1
      };
      this.$axios
        .post("/case/getcase/", data)
        .then(res => {
          if (res.data.status == 200) {
            this.total_num = res.data.pagecount;
            // console.log(res.data);
            this.tableData = res.data.case_list;
            // console.log("处理成功");
          }
        })
        .catch(err => {
          this.$message.error(err.message);
        });
    }

  

猜你喜欢

转载自www.cnblogs.com/Jack-cx/p/12081769.html