本来想通过列表中每个对象的某个属性绑定到checkbox的状态,但是发现有个问题:就是点击复选框后,数据确实改变了,但是视图没有改变,当点击其他row的时候,才会更新之前的数图。如下图,第1次勾选第一行没反应,再点击其他行才会更新视图。

<el-table-column label="是否绑定" min-width="50">
 	<template slot-scope="scope">
        <el-checkbox v-model="scope.row.binded">是否绑定</el-checkbox>
    </template>
</el-table-column>

在这里插入图片描述

解决方法:通过数据驱动视图更新

el-checkbox绑定一个自定义属性,比如data-a=responsive,当点击复选框后,会触发@change事件,在事件处理函数中,改变responsive的值,就会让视图发生更新。

<el-table-column label="是否绑定" min-width="50">
    <template slot-scope="scope">
        <el-checkbox v-model="scope.row.binded"  :data-a="responsive" @change="update()">是否绑定</el-checkbox>
    </template>
</el-table-column>

<script>
export default {
	data() {
        return {
        	responsive: true
        }
    }
	method: {
		update(){
		    this.responsive = !this.responsive //数据驱动vue视图更新,解决checkbox视图不更新的问题
		},
	}
}
</script>

GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:1 个月前 )
c345bb45 5 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 5 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐