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);
        });
    }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM