Is there a callback method like on-shown and on-show using vue.js?
I'm using v-show="my-condition" on a div element. But inside are some charts.js charts, which cannot render unless visible.
Anyone know how can render the chart.js only when the parent is made visible? They are inside selectable tabs so it fires potentially multiple times.
I'm using Vue.js and vue-strap.
Is there a callback method like on-shown and on-show using vue.js?
I'm using v-show="my-condition" on a div element. But inside are some charts.js charts, which cannot render unless visible.
Anyone know how can render the chart.js only when the parent is made visible? They are inside selectable tabs so it fires potentially multiple times.
I'm using Vue.js and vue-strap.
Share Improve this question asked Jan 2, 2016 at 2:06 Douglas RosebankDouglas Rosebank 1,8372 gold badges14 silver badges11 bronze badges 3 |3 Answers
Reset to default 7Check out this answer - using nextTick()
worked for me in a similar situation. In a nutshell:
new Vue({
...
data: {
myCondition: false
},
watch: {
myCondition: function () {
if (this.myCondition) {
this.$nextTick(function() {
// show chart
});
} else {
// hide chart
}
}
},
...
})
There is no event
that you describe.
However, you could use a computed
property like this:
new Vue({
...
data: {
myCondition: false
},
computed: {
showChart: function () {
if (this.myCondition) {
// show chart
} else {
// hide chart
}
return this.myCondition
}
},
...
})
<div v-show="showChart"></div>
https://jsfiddle.net/xhfo24qx/
custom-directive
may archive this goals this goal
for example: https://stackoverflow.com/a/49737720/4896468
docs: https://v2.vuejs.org/v2/guide/custom-directive.html
.$watch
it and use the callback to render the tables. See the docs – JCOC611 Commented Jan 2, 2016 at 2:13v-if
instead ofv-show
and use a directive on the element you are making into a chart so you don't need to worry about watching. – Bill Criswell Commented Jan 2, 2016 at 17:48