I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.
In the column headers, I would like to display input fields to filter the data but I want to display these inputs only on demand (upon clicking a button). So I wanted to use custom headers like this:
<el-table-column prop="name" label="Name" width="180">
<template slot="header">
Name <br/>
<!-- show input only on demand -->
<el-input v-show="bool"></el-input>
</template>
</el-table-column>
And here es the problem: nothing happens when the value of bool changes.
After a few testing I realized that the header template doesn't seem to be reactive.
I've found a workaround to toggle my inputs: forcing the el-table to re-render...
<el-table v-if="showTable" ...>
methods: {
toggleInputs() {
// toggle bool
this.bool = !this.bool;
// force re-render table...
this.showTable = false;
this.$nextTick(() => (this.showTable = true));
}
}
It works. But this is not clean at all and it takes some time to re-render a not-so large table...
Here is the full example: /
Has someone a better solution to make custom headers reactive?
I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.
In the column headers, I would like to display input fields to filter the data but I want to display these inputs only on demand (upon clicking a button). So I wanted to use custom headers like this:
<el-table-column prop="name" label="Name" width="180">
<template slot="header">
Name <br/>
<!-- show input only on demand -->
<el-input v-show="bool"></el-input>
</template>
</el-table-column>
And here es the problem: nothing happens when the value of bool changes.
After a few testing I realized that the header template doesn't seem to be reactive.
I've found a workaround to toggle my inputs: forcing the el-table to re-render...
<el-table v-if="showTable" ...>
methods: {
toggleInputs() {
// toggle bool
this.bool = !this.bool;
// force re-render table...
this.showTable = false;
this.$nextTick(() => (this.showTable = true));
}
}
It works. But this is not clean at all and it takes some time to re-render a not-so large table...
Here is the full example: https://jsfiddle/olivierlevrey/pyvc6kht/2/
Has someone a better solution to make custom headers reactive?
Share Improve this question edited Sep 11, 2019 at 13:16 41 72 6c 1,7806 gold badges22 silver badges36 bronze badges asked Sep 11, 2019 at 12:57 Olivier LevreyOlivier Levrey 1151 silver badge10 bronze badges1 Answer
Reset to default 5Looks like your template is not recognizing the scope. Adding slot-scope
solves your problem.
https://jsfiddle/cz8tm9bd/
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744843693a4596708.html
评论列表(0条)