vue中實(shí)現(xiàn)可編輯table及其中加入下拉選項(xiàng)
可編輯table及其中加入下拉選項(xiàng)
<template>
?? ?<div>
?? ?
? ? ? ? <el-table :data="tabledatas" border>
? ? ? ? ? ? <el-table-column label="姓名">
? ? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? ? ? <el-input placeholder="請(qǐng)輸入內(nèi)容" v-show="scope.row.show" v-model="scope.row.name"></el-input>
? ? ? ? ? ? ? ? ? ? <span v-show="!scope.row.show">{{scope.row.name}}</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-table-column>
? ? ? ? ? ??
? ? ? ? ? ? <el-table-column label="年齡">
? ? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? ? ? <el-input placeholder="請(qǐng)輸入內(nèi)容" v-show="scope.row.show" v-model="scope.row.age"></el-input>
? ? ? ? ? ? ? ? ? ? <span v-show="!scope.row.show">{{scope.row.age}}</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-table-column>
? ? ? ? ? ? <el-table-column label="地址">
? ? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? ? ? <el-input placeholder="請(qǐng)輸入內(nèi)容" v-show="scope.row.show" v-model="scope.row.address"></el-input>
? ? ? ? ? ? ? ? ? ? <span v-show="!scope.row.show">{{scope.row.address}}</span>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-table-column>
? ? ? ? ? ? <el-table-column label="學(xué)籍">
? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? <span v-show="!scope.row.show">{{scope.row.stu}}</span>
? ? ? ? ? ? ? <el-select v-model="scope.row.stu" placeholder="請(qǐng)選擇" v-show="scope.row.show" >
? ? ? ? ? ? ??
? ? ? ? ? ? ? ? <el-option
? ? ? ? ? ? ? ? ? v-for="item in options"
? ? ? ? ? ? ? ? ? :key="item.stu"
? ? ? ? ? ? ? ? ? :label="item.stu"
? ? ? ? ? ? ? ? ? :value="item.stu">
? ? ? ? ? ? ? ? </el-option>
? ? ? ? ? ? ? </el-select>
? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-table-column>
? ? ? ? ? ? <el-table-column label="操作">
? ? ? ? ? ? ? ? <template slot-scope="scope">
? ? ? ? ? ? ? ? ? ? <el-button @click="scope.row.show =true" >編輯</el-button>
? ? ? ? ? ? ? ? ? ? <el-button @click="scope.row.show =false">保存</el-button>
? ? ? ? ? ? ? ? </template>
? ? ? ? ? ? </el-table-column>
? ? ? ? </el-table>
? ? ? </div>?
</template><script>
export default {
data(){
return {
options: [{
value: '選項(xiàng)1',
stu: '初中'
}, {
value: '選項(xiàng)2',
stu: '高中'
}, {
value: '選項(xiàng)3',
stu: '大專'
}, {
value: '選項(xiàng)4',
stu: '本科'
}, {
value: '選項(xiàng)5',
stu: '博士'
}],
value: '',
tabledatas: [
{ name: '李一', age: '19',address:"寧波",stu:"本科",show:false},
{ name: '郭明', age: '23',address:"四川",stu:"本科",show:false},
{ name: '天天', age: '12',address:"海南",stu:"初中",show:false},
{ name: '隆', age: '40',address:"上海",stu:"博士",show:false},
],
}
}
</script>
可以通過(guò)設(shè)置js里的show:true讓該行處于默認(rèn)編輯狀態(tài)
出來(lái)效果圖

vue表頭下拉選擇框使用總結(jié)
1.在el-table-culumn中,加入template標(biāo)簽
使用:
<template slot="header" slot-scope="scope"> ? <el-dropdown trigger="click" @command = "handleCommand"> ? ? <span>類型</span> ? ? <el-dropdown-menu slot="dropdown"> ? ? ? <el-radio-group v-model="sx">//這里,會(huì)出現(xiàn)一個(gè)bug,下文有解決辦法 ? ? ? ? <el-dropdown-item command="屬性0"><el-radio label="0">屬性0</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性1"><el-radio label="1">屬性1</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性2"><el-radio label="2">屬性2</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性3"><el-radio label="3">屬性3</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性4"><el-radio label="4">屬性4</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性5"><el-radio label="5">屬性5</el-radio> </el-dropdown-item> ? ? ? ? <el-dropdown-item command="屬性6"><el-radio label="6">屬性6</el-radio> </el-dropdown-item> ? ? ? </el-radio-group> ? ? </el-dropdown-menu> ? </el-dropdown> </template> <template slot-scope="scope">(表中元素)</template>
2.設(shè)置handleCommand方法
(當(dāng)時(shí)沒(méi)使用handleCommand方法做緩沖,在刷新時(shí),第一次刷新不會(huì)賦值,第二次刷新會(huì)得到上次刷新的值。)
handleCommand(command) {
? if(command == '屬性0' ){
? ? this.sx= '0'
? } else if (command === '屬性1') {
? ? this.sx = '1'
? } else if( command === '屬性2') {
? ? this.sx = '2'
? } else if (command === '屬性3') {
? ? this.sx = '3'
? } else if (command === '屬性4') {
? ? this.sx = '4'
? } else if( command === '屬性5') {
? ? this.sx = '5'
? } else if (command === '屬性6') {
? ? this.sx = '6'
? }
? this.刷新方法;
},但是在使用過(guò)程中,點(diǎn)擊下拉框中數(shù)據(jù)時(shí),會(huì)出現(xiàn)執(zhí)行兩次handleCommand()方法的情況。通過(guò)一天的詢問(wèn)與查找,得到解決辦法。
問(wèn)題出現(xiàn)在<el-radio>標(biāo)簽上,當(dāng)點(diǎn)擊框中數(shù)據(jù)時(shí),數(shù)據(jù)響應(yīng)一次handleCommand()方法,<el-radio>也會(huì)響應(yīng)一次handleCommand()方法。
所以,應(yīng)該去掉<el-radio>標(biāo)簽與<el-radio-group>標(biāo)簽。
<template slot="header" slot-scope="scope"> ? <el-dropdown trigger="click" @command = "handleCommand"> ? ? <span>類型</span> ? ? <el-dropdown-menu slot="dropdown"> ? ? ? <el-dropdown-item command="屬性0">屬性0</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性1">屬性1</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性2">屬性2</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性3">屬性3</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性4">屬性4</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性5">屬性5</el-dropdown-item> ? ? ? <el-dropdown-item command="屬性6">屬性6</el-dropdown-item> ? ? </el-dropdown-menu> ? </el-dropdown> </template> <template slot-scope="scope">(表中元素)</template>
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue使用antd中input組件去驗(yàn)證輸入框輸入內(nèi)容(rules?案例)
這篇文章主要介紹了Vue使用antd中input組件去驗(yàn)證輸入框輸入內(nèi)容-rules-案例,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
vue使用el-select下拉框匹配不到值的問(wèn)題及解決
這篇文章主要介紹了vue使用el-select下拉框匹配不到值的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05
解決Vue的項(xiàng)目使用Element ui 走馬燈無(wú)法實(shí)現(xiàn)的問(wèn)題
這篇文章主要介紹了解決Vue的項(xiàng)目使用Element ui 走馬燈無(wú)法實(shí)現(xiàn)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
vue2前端使用axios發(fā)起post請(qǐng)求后端(springboot)接收不到值解決辦法
這篇文章主要介紹了vue2前端使用axios發(fā)起post請(qǐng)求后端(springboot)接收不到值解決辦法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-03-03
Vue3+Canvas實(shí)現(xiàn)坦克大戰(zhàn)游戲(二)
本文主要給大家講解一下子彈擊中物體、物體銷毀、敵方坦克構(gòu)建生成、運(yùn)動(dòng)算法、爆炸效果、以及障礙物的生成,感興趣的小伙伴可以了解一下2022-03-03

