• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

iview table render集成switch开关的实例

vue 搞代码 4年前 (2022-01-08) 18次浏览 已收录 0个评论

下面小编就为大家分享一篇iview table render集成switch开关的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

今天想要分享的是iview table render集成switch开关修改table表格的值,看文档记得看2.0的,不注意打开就成1.0然后用上了一直没有效果又没有找出原因。给出的只是一种写法思路,具体自己集成。

一、效果如下

即是打开处理switch开关,对应修改为已处理状态,关闭switch开关,修改为未处理状态。

二、template html写法

 <span style="font-size:14px"><table border></table></span>

三、data写法,table render函数写法,

 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', { //数据库1是已处理,0是未处理 props: { type: 'primary', value: params.row.treatment === 1 //控制开关的打开或关闭状态,官网文档属性是value }, style: { marginRight: '5px' }, on: { 'on-change': (value) => {//触发事件是on-change,用双引号括起来, //参数value是回调值,并没有使用到 this.switch(params.index) //params.index是拿到table的行序列,可以取到对应的表格值 } } }, ) ]); } }]

四、methods方法

 //通过开关状态判断值然后传值进行更新 switch(index) { //打开是true,已经处理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 = { i<p style="color:transparent">本文来源gao!daima.com搞$代!码网</p>d: id } data[key] = value vm.$http.put('/v1/suggestion', data).then(function (response) { if (response.data.code == '000000') { vm.$Message.info('更新成功'); vm.getFeedbackMessages()//获取table数据信息,这里调用是因为修改值之后马上可以更新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) }) },

注重思路,有问题一起交流

以上就是iview table render集成switch开关的实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:iview table render集成switch开关的实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址