【vue element-ui 】el-table中使用checkbox视图更新滞后

本来想通过列表中每个对象的某个属性绑定到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="checked" @change="update()">是否绑定</el-checkbox>
    </template>
</el-table-column>

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

猜你喜欢

转载自blog.csdn.net/SingDanceRapBall/article/details/131425852