鍍金池/ 問答/HTML/ vue中的一張form表單怎么樣在接收數(shù)據(jù)的同時(shí)又把數(shù)據(jù)反給后端

vue中的一張form表單怎么樣在接收數(shù)據(jù)的同時(shí)又把數(shù)據(jù)反給后端

clipboard.png
類似這么一張表單,第一行的產(chǎn)品名稱和產(chǎn)品型號需要從后端去取數(shù)據(jù),但又要把表中填的所有數(shù)據(jù)再反給后端接口,需要在el-from中怎么綁定值。

假設(shè)代碼是這樣子的

第一部分為布局代碼

    <el-form :model="list" label-width="90px" class="form_border">
        <el-form-item label="產(chǎn)品名稱">
          <el-input v-model="list.Name"></el-input>
        </el-form-item>
     
      
        <el-form-item label="產(chǎn)品型號">
          <el-input v-model="list.Spec"></el-input>
        </el-form-item>
      
        <el-form-item label="抽檢數(shù)量">
          <el-input v-model="list.Num></el-input>
        </el-form-item>
      
        <el-form-item label="檢驗(yàn)時(shí)間">
          <el-date-picker v-model="list.Date" type="date" placeholder="選擇日期">
          </el-date-picker>
        </el-form-item>
    </el-form>

第二部分為js代碼

data() {
  return {
    list: null,
    updata:{
        Name:undefind,
        Spec:undefind,
        Num:undefind,
        Date:undefind,
    },
  },
  
//發(fā)送填寫數(shù)據(jù)的接口
update(item) {
  const param = {
    Name: this.updata.Name,
    Spec: this.updata.Spec,
    Num: this.updata.Num,
    Date: this.updata.Date,
  };
  api.updataInfo(param).then(response => {
    if (response.data.Success) {
      this.$notify({
        title: "成功",
        message: "更新成功",
        type: "success",
        duration: 2000
      });
    } else {
      this.$notify({
        title: "失敗",
        message: response.data.Message,
        type: "error",
        duration: 2000
      });
    }
  });
},

//獲取后端的數(shù)據(jù)的一個(gè)接口
getDInfo(){
    const param = {
      id: this.recordPKID
    };
    api.getdinfo(param).then(response => {
      const data = response.data;
      this.list= data;
    });
  },

想請教一下大佬們<el-form>中 :model后面的值需要怎么去綁,因?yàn)閯偨佑|不久不太了解,所以想問問需要怎么操作、有什么方法,如果表述的比清楚可以留言問我,謝謝??!

回答
編輯回答
爆扎

同樣的內(nèi)容在前端用同樣的變量比較好,最好不要分開.如果內(nèi)容不同,可以在事件觸發(fā)的時(shí)候把數(shù)據(jù)復(fù)制一遍,但原則上保持前端顯示的內(nèi)容和vue的變量一對一的關(guān)系.一對多的綁定肯定沒這么做的.

2018年4月14日 05:43
編輯回答
愛礙唉

沒太明白你要干什么。你現(xiàn)在有什么問題嗎?

你綁的沒問題。

2017年6月19日 16:38