zoukankan      html  css  js  c++  java
  • 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);
            });
        }
    

      

  • 相关阅读:
    Python 简单入门指北(一)
    React Native 从入门到原理一
    WWDC 17: 开发者的最初观感
    写给程序员的管理入门课程 -《格鲁夫给经理人的第一课》
    RxSwift之路 1#Swift语法知识准备
    猿题库从 Objective-C 到 Swift 的迁移
    谈一谈iOS事件的产生和传递
    李洪强原创博客01
    re.S、 re.M
    1111111
  • 原文地址:https://www.cnblogs.com/Jack-cx/p/12081769.html
Copyright © 2011-2022 走看看