el-select 選擇框岭埠,選擇之后傳值梁棠,萬(wàn)一要傳多個(gè)值怎么辦秃诵,v-model只綁定了一個(gè)值靠闭。
解決方法: 加入監(jiān)聽(tīng)事件 @change="getName(temp.communityId)"
以下是vue文件代碼
<el-form-item :label="$t('table.communityName')" prop="communityName">
<el-select
class="filter-item"
v-model="temp.communityId"
:disabled="read"
:placeholder="$t('table.communityName')"
@change="getName(temp.communityId)"
>
<el-option
v-for=" item in listcomm"
:key="item.communityId"
:label="item.communityName"
:value="item.communityId"
></el-option>
</el-select>
<!-- <span v-if="show == false">{{temp.communityName = item.communityName}}</span> -->
</el-form-item>
以下是js代碼,getComm() 獲取到列表帐我,getName()循環(huán)這個(gè)列表,找到與id相同的愧膀,取得communityName
getName(val) {
val = this.temp.communityId
var array = this.getComm()
for (let index = 0; index < array.length; index++) {
const element = array[index].communityId;
if (element == val) {
this.temp.communityName = array[index].communityName
}
}
return this.temp.communityName
},
getComm() {
listcommunity().then((response) => {
this.listcomm = response.data
})
return this.listcomm
},
//這個(gè)方法是通過(guò)后臺(tái)接口拦键,直接取得對(duì)應(yīng)的值
// getName(val) {
// val = this.temp.communityId
// getestatebyid(val).then((response) => {
// this.temp.communityName = response.data.communityName
// })
// return this.temp.communityName
// },
繼續(xù)研究下能不能直接傳數(shù)組