vue+antd中table动态隐藏显示列数据

应用场景:table中老师、学生、年龄三列,当搜索学生时3列都显示,当搜索老师时学生列不显示,默认搜索值为学生

table中columns的数据如下:

const columns = [
  {
    title: '老师',
    dataIndex: 'teacher',
    ellipsis: true
  },
  {
    title: '学生',
    dataIndex: 'student',
    ellipsis: true
  },
  {
    title: '年龄',
    dataIndex: 'age',
    ellipsis: true
  }
]

解决办法如下:


    handleSearchFun(type) {
      const studentObj= {
         title: '学生',
         dataIndex: 'student',
         ellipsis: true
      }
      type === '老师' ? columns.splice(1, 1) : columns.splice(1, 0, teacherObj)
    }

猜你喜欢

转载自blog.csdn.net/Lucky_girl_wan/article/details/120508999