iview table render集成switch開(kāi)關(guān)的實(shí)例
今天想要分享的是iview table render集成switch開(kāi)關(guān)修改table表格的值,看文檔記得看2.0的,不注意打開(kāi)就成1.0然后用上了一直沒(méi)有效果又沒(méi)有找出原因。給出的只是一種寫(xiě)法思路,具體自己集成。
一、效果如下

即是打開(kāi)處理switch開(kāi)關(guān),對(duì)應(yīng)修改為已處理狀態(tài),關(guān)閉switch開(kāi)關(guān),修改為未處理狀態(tài)。
二、template html寫(xiě)法
<span style="font-size:14px;"><Table highlight-row border :columns="columns1" :data="data1" ref="table" :height="tableHeight"></Table></span>
三、data寫(xiě)法,table render函數(shù)寫(xiě)法,
columns1: [{
fixed: 'right',
title: 'Action',
key: 'action',
width: 250,
align: 'center',
render:(h, params) => {
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '20px'
},
on: {
click: () => {
this.show(params.index)
}
}
}, '閱覽'),
h('strong', {
style: {
marginRight: '5px'
},
}, '處理'),
h('i-switch', { //數(shù)據(jù)庫(kù)1是已處理,0是未處理
props: {
type: 'primary',
value: params.row.treatment === 1 //控制開(kāi)關(guān)的打開(kāi)或關(guān)閉狀態(tài),官網(wǎng)文檔屬性是value
},
style: {
marginRight: '5px'
},
on: {
'on-change': (value) => {//觸發(fā)事件是on-change,用雙引號(hào)括起來(lái),
//參數(shù)value是回調(diào)值,并沒(méi)有使用到
this.switch(params.index) //params.index是拿到table的行序列,可以取到對(duì)應(yīng)的表格值
}
}
}, )
]);
}
}]
四、methods方法
//通過(guò)開(kāi)關(guān)狀態(tài)判斷值然后傳值進(jìn)行更新
switch(index) {
//打開(kāi)是true,已經(jīng)處理1
if (this.data1[index].treatment == 1) {
this.data1[index].treatment = 0
this.updateFeedbackMessage(this.data1[index].id, 'treatment', this.data1[index].treatment)
} else {
this.updateFeedbackMessage(this.data1[index].id, 'treatment', 1)
}
},
//更新反饋信息某一字段
updateFeedbackMessage(id, key, value) {
var vm = this
var data = {
id: id
}
data[key] = value
vm.$http.put('/v1/suggestion', data).then(function (response) {
if (response.data.code == '000000') {
vm.$Message.info('更新成功');
vm.getFeedbackMessages()//獲取table數(shù)據(jù)信息,這里調(diào)用是因?yàn)樾薷闹抵篑R上可以更新table值
}
}).catch((error) => {
console.log(error)
})
},
//獲取所有反饋信息列表
getFeedbackMessages() {
var vm = this
var url = '/v1/suggestions?'
url = url + "pageNum=" + this.pageNum + '&pageSize=' + this.pageSize
if (this.createByValue != '') {
url = url + '&createBy=' + this.createByValue
}
if (this.dealModelValue != '') {
url = url + '&treatment=' + this.dealModelValue
}
this.$http.get(url).then(response => {
if (response.data.code == '000000') {
vm.data1 = response.data.data
vm.pageTotal = parseInt(response.data.message)
}
}).catch(error => {
console.log(error)
})
},
注重思路,有問(wèn)題一起交流
以上這篇iview table render集成switch開(kāi)關(guān)的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vue+Element-UI中el-table動(dòng)態(tài)合并單元格:span-method方法代碼詳解
el-table是element-ui提供的表格組件,可以用于展示和操作數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于Vue+Element-UI中el-table動(dòng)態(tài)合并單元格:span-method方法的相關(guān)資料,需要的朋友可以參考下2023-09-09
使用Vue-Awesome-Swiper實(shí)現(xiàn)旋轉(zhuǎn)疊加輪播效果&平移輪播效果
這篇文章主要介紹了用Vue-Awesome-Swiper實(shí)現(xiàn)旋轉(zhuǎn)疊加輪播效果&平移輪播效果,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值需要的朋友可以參考下2019-08-08
詳解vue項(xiàng)目打包后通過(guò)百度的BAE發(fā)布到網(wǎng)上的流程
這篇文章主要介紹了將vue的項(xiàng)目打包后通過(guò)百度的BAE發(fā)布到網(wǎng)上的流程,主要運(yùn)用的技術(shù)是vue+express+git+百度的應(yīng)用引擎BAE。需要的朋友可以參考下2018-03-03
form?表單驗(yàn)證是異步問(wèn)題記錄(推薦)
這篇文章主要介紹了form?表單驗(yàn)證是異步問(wèn)題記錄,通過(guò)實(shí)例代碼介紹了Promise.all 和 Promise.allSettled 區(qū)別,需要的朋友可以參考下2023-01-01
vant 解決tab切換插件標(biāo)題樣式自定義的問(wèn)題
這篇文章主要介紹了vant 解決tab切換插件標(biāo)題樣式自定義的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11
VueX瀏覽器刷新如何實(shí)現(xiàn)保存數(shù)據(jù)
這篇文章主要介紹了VueX瀏覽器刷新如何實(shí)現(xiàn)保存數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07

