話(huà)嘮不話(huà)嘮,直接說(shuō)正題!
大概代碼如下,在一個(gè)可展開(kāi)的table里,點(diǎn)擊展開(kāi)按鈕,加載select組件。
<!-- 省略前面代碼 -->
<!-- expandable table information -->
<el-table-column type="expand">
<template>
<el-form :inline="true" :model="formInline" size="mini" >
<el-form-item label="查看方式">
<el-select v-model="formInline.region" placeholder="select">
<el-option label="區(qū)域一" value="shanghai"></el-option>
<el-option label="區(qū)域二" value="beijing"></el-option>
</el-select>
</el-form-item>
</el-form>
</template>
</el-table-column>
<!-- 省略后面代碼 -->
<script>
export default {
data() {
return {
formInline: {
user: '',
region: ''
}
}
}
}
</script>
以上內(nèi)容均復(fù)制自element-ui官網(wǎng)

效果
當(dāng)table表格展開(kāi)后,加載一個(gè)下拉框,再點(diǎn)擊下拉框加載其他內(nèi)容。
但是這時(shí)會(huì)發(fā)現(xiàn),無(wú)論選中什么,都不會(huì)回顯。
在網(wǎng)上查了類(lèi)似都問(wèn)題,大多數(shù)都是因?yàn)楫惒郊虞d導(dǎo)致都,解決方法大概有兩類(lèi),如下:
1. this.$forceUpdate();
2. this.$set(targetObject,targetKey,targetValue);
兩種方式我都嘗試了,并不適合。
經(jīng)過(guò)各種嘗試,找到了適合自己都第三種方式,僅供大家參考:
<!-- 省略前面代碼 -->
<!-- expandable table information -->
<el-table-column type="expand">
<!-- 在template模板上添加屬性 slot-scope="scope" -->
<template slot-scope="scope">
<el-form :inline="true" :model="formInline" size="mini" >
<!-- 省略中間代碼 -->
</el-form>
</template>
</el-table-column>
<!-- 省略后面代碼 -->