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.
The v-show directive is a Vue. js directive used to toggle the display CSS property of a element with our data via inline styles. If the data is true it will make it visible else it will make it invisible.
The v-bind directive is a Vuejs directive used to bind one or more attributes, or a component prop to an element. If that attribute is binded to our data defined in Vuejs instance then dynamically changes can be observed as data changes.
Vue gives you a bunch of good ways to hide the element on the screen. When using v-if="false" the element isn't rendered at all in the DOM. When using v-show="false" the element is rendered in the DOM, however, Vue applies the inline style display: none that hides the element completely.
Using watchers in Vue # vue file we can watch for changes in data or props by using watch . For example, the below code will watch for a change in the data element pageData , and run a function according to the value it is changed to.
Check 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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With