vue中使用el-table复选框选中不了

:data 使用 filter() 等方法返回新数组/新引用时,复选框会失效

image

 解决方法:

  • 不要在模板 :data 里直接写 filter
  • 把过滤逻辑放到 computed 计算属性 里
  • 用计算属性给表格绑定数据
<el-table ref="multipleTable" v-loading="tableLoading" :data="filteredTableData" >


export default {
  data() { ... },
  
  // 新增 —— 计算属性
  computed: {
    // 过滤后的数据
    filteredTableData() {
      return this.tableData_pp.filter(data => 
        !this.search_pp || 
        data.partNo.toLowerCase().includes(this.search_pp.toLowerCase()) || 
        data.targetLocationNo.toLowerCase().includes(this.search_pp.toLowerCase()) || 
        data.partDesc.toLowerCase().includes(this.search_pp.toLowerCase())
      )
    }
  },

  methods: { ... }
}

 

posted @ 2026-05-20 10:27  何以平天下  阅读(6)  评论(0)    收藏  举报