admin管理员组文章数量:1221253
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
本文标签: javascriptCallback for vshow in vuejsStack Overflow
版权声明:本文标题:javascript - Callback for v-show in vue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739253093a2155008.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