鍍金池/ 問答/HTML/ vue 獲取數(shù)據(jù)為什么獲取不到已經(jīng)更新的數(shù)據(jù)?

vue 獲取數(shù)據(jù)為什么獲取不到已經(jīng)更新的數(shù)據(jù)?

1.去后臺獲取數(shù)據(jù),可以獲取的到。
2.之后在提交數(shù)據(jù)(更新表單),確認表單數(shù)據(jù)提交上去了。在獲取數(shù)據(jù),獲取不到已經(jīng)修改的數(shù)據(jù),這是為什么?

這是表單:

<el-dialog title="修改個人資料" :visible.sync="personalDetailVisible">
  <el-form :model="personalForm" :rules="personalFormRules" ref="ruleForm2">
    <el-form-item label="用戶名" prop="personUserName">
      <el-input v-model="personalForm.personUserName" :disabled="true"></el-input>
    </el-form-item>

    <el-form-item label="QQ" prop="qq">
      <el-input placeholder="請輸入QQ號" v-model="personalForm.qq"></el-input>
    </el-form-item>

    <el-form-item label="微信" prop="weixin">
      <el-input placeholder="請輸入微信號" v-model="personalForm.weixin"></el-input>
    </el-form-item>

    <el-form-item label="手機" prop="cellphone">
      <el-input placeholder="請輸入手機號" v-model="personalForm.cellphone"></el-input>
    </el-form-item>

    <el-form-item label="郵箱" prop="email">
      <el-input placeholder="請輸入郵箱" v-model="personalForm.email"></el-input>
    </el-form-item>

    <el-form-item label="電話" prop="phone">
      <el-input placeholder="起輸入電話號碼" v-model="personalForm.phone"></el-input>
    </el-form-item>

    <el-form-item label="所屬部門" prop="department">
      <el-input placeholder="起輸入所屬部門" v-model="personalForm.department"></el-input>
    </el-form-item>

    <el-form-item label="角色" prop="role">
      <el-input v-model="personalForm.role" :disabled="true"></el-input>
    </el-form-item>
    <el-button type="primary" @click="savePerDetail('ruleForm2')">更新</el-button>
    <el-button type="primary" @click="changePerDetGoBack">返回</el-button>
  </el-form>
</el-dialog>

這是獲取數(shù)據(jù)的JS:

  getuserdata() {
    let _this = this;
    this.$axios({
      method: "post",
      url: "/api/authController/getMenus",
      data: qs.stringify({
        token: this.token
      })
    }).then((response) => {
      console.log(response)
      let res = response.data.message.user;
      _this.username = res.username;
      _this.gender = res.gender;
      _this.qq = res.qq;
      _this.dianhua = res.phone;
      _this.wechat = res.wechat;
      _this.phone = res.mobile;
      _this.email = res.email;
      _this.realname = res.realname;
      _this.position = res.position;
      _this.department = res.department;
      if (res.roleCode === "user") {
        _this.roleCode = "用戶"
      }
      if (res.roleCode === "administartor") {
        _this.roleCode = "管理員"
      }
    })
  },
  
  這是提交數(shù)據(jù)的JS:
        // 更新個人資料按鈕
  savePerDetail(formName) {
      let _this = this;
      this.$refs[formName].validate((valid)=>{
        if (valid) {
          this.$axios({
            method: 'post',
            url:'/api/userController/update',
            data: qs.stringify({
              token: this.token,
              id: this.userId,
              username: this.username,
              qq: this.personalForm.qq,
              wechat: this.personalForm.wexin,
              mobile: this.personalForm.cellphone,
              email: this.personalForm.email,
              phone: this.personalForm.phone,
              department: this.personalForm.department,
            })
          }).then((res)=>{
            console.log(res)
            if (res.data.code === 200) {
              // this.getuserdata();
            }
          })
        }
      })
  },
  
  然后就是獲取不到新的提交上去的數(shù)據(jù) 這是為啥啊? 求大佬解答
回答
編輯回答
陌如玉

1.看你問題的描述應(yīng)該是你提交給后端之后重新查詢數(shù)據(jù),獲取到的還是舊的數(shù)據(jù)
2.所以確認一下,你獲取到的數(shù)據(jù)到底是新的還是舊的,是在頁面上看到的,還是在瀏覽器的devtool里看到的
3.如果在devtool看到的是舊的,那么看一下你傳的參數(shù)是不是有問題,沒問題就去找后端
4.如果是devtool看到的是新的,那么就是你的代碼寫的有問題,頁面沒有和數(shù)據(jù)同步

2018年4月26日 20:42