vue+Element 實(shí)現(xiàn)table表格可編輯(select下拉框 input輸入框)

實(shí)現(xiàn)思路:

  1. 聚焦在當(dāng)前行的時(shí)候,可以進(jìn)行文本的編輯,或者下拉框的選擇,主要用到 highlight-current-row 這個(gè)樣式

  2. 借助template組件進(jìn)行編輯

具體代碼如下:

<el-table :data="columnData" class="tb-edit" style="width: 100%;margin-top: 20px" highlight-current-row @row-click="handleCellChange">
        <el-table-column prop="columnName" label="字段">
            <template scope="scope" >
                <el-input size="small" v-model="scope.row.columnName" placeholder="請(qǐng)輸入內(nèi)容" @change="handleCellEdit(scope.$index, scope.row)"></el-input>
                    <span>{{scope.row.columnName}}</span>
            </template>
        </el-table-column>
                    
        <el-table-column prop="isSensitive" label="敏感字段" width="120">
            <template scope="scope">
                <el-select v-model="scope.row.isSensitive"  @change="handleCellEdit(scope.$index, scope.row)">
                    <el-option v-for="item in sensitiveOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
                <el-button type="text" size="small" @click.native.prevent="deleteRow(scope.$index, columnData)">刪除</el-button>
                </template>
        </el-table-column>
</el-table>

css樣式:

.tb-edit .el-input {
    display: none
}
.tb-edit .current-row .el-input  {
    display: block
}
.tb-edit .current-row .el-input+span {
    display: none
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容