常规写法都是把filters写死了的
columns: [
..., {
...,
filters: [{
label: 'Greater than 25',
value: 1
}, {
label: 'Less than 25',
value: 2
}],...
},...
]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
但是有时候我们需要的是可以根据后台所给的数据初始化filters,这时候需要做的并不是filters: this.variable
,而是:
function(variable) {
this.columns[index].filters = variable;
}
- 1
- 2
- 3
iView table组件会监听columns和data的改变而重新渲染。
但是如果是写成上述filters: this.variable
方式
- 首先vue加载的时候运行到
this.variable
,此时this.variable
的值为undefined - 然后table组件并不会监听到columns的变化而重新渲染,至于监听不到的原因可以去查看源码(我是不会说我找不到证据的)