鍍金池/ 問答/HTML/ vue中子組件像父組件傳遞的值不能動態(tài)綁定到父組件頁面上

vue中子組件像父組件傳遞的值不能動態(tài)綁定到父組件頁面上

問題出現(xiàn)在子組件像父組件傳遞參數(shù)上,子組件傳遞的函數(shù)如下:

// 某一行被雙擊時觸發(fā)
rowDblclik(row, event) {
  const houseData = `【${row.houseSort}】,【${row.houseType}】,${
    row.address
  }`;
  const houseId = row.houseId;
  this.$emit("select-house", houseData, houseId);
  this.formVisible=false
},

這時候我嘗試在父組件進(jìn)行獲取,證明父組件匯總是可以獲得傳遞來的參數(shù),但是不能動態(tài)的綁定到頁面上,這是我父組件相關(guān)部分的代碼:

        // 從組件中傳遞
    selectHouse(houseData, houseId) {
      this.agreeForm.houseName  = houseData;
      this.selectHouseId=houseId
      console.log(this.agreeForm.houseName)
    }
  }
    // 頁面代碼如下
   <el-form-item label="住房分配" prop="agreeState">
   <el-input v-model="agreeForm.houseName" size="small" readonly placeholder="請選擇住房">
   <el-button slot="append" icon="el-icon-search" @click="dialogVisible=!dialogVisible"></el-button>
   </el-input>
  </el-form-item>

問題截圖如下,可以console到該數(shù)據(jù),但是不能在頁面顯示

clipboard.png

回答
編輯回答
風(fēng)畔

應(yīng)該是this.$emit(eventName,arg);是不是不能像你那樣寫,可以this.$emit("select-house", [houseData, houseId]);
接受selectHouse(data) {

  this.agreeForm.houseName  = data[0];
  this.selectHouseId=data[1]
  console.log(this.agreeForm.houseName)
}
2018年7月9日 11:30
編輯回答
亮瞎她

打印是有的,那有可能是vue沒有檢測到你數(shù)值的變化,可以使用 this.$set(this.agreeForm,houseName,houseData)試試

2018年3月19日 19:44