简体   繁体   English

V-斗篷的Vue.js生命周期挂钩

[英]Vue.js life-cycle hook for v-cloak

I'm working on a project where v-cloak is styled with display: none , and decorates the body. 我正在一个项目中,其中v斗篷的样式为display: none ,并装饰身体。 This means everything is hidden until the Vue instance is ready. 这意味着一切都将被隐藏,直到Vue实例准备就绪为止。

I've made a component that inserts a chart (using highcharts ). 我已经制作了一个插入图表的组件(使用highcharts )。 The component is inserted on ready , yet the chart does not display correctly. 组件已插入ready ,但图表无法正确显示。

Here is a jsfiddle demonstrating the problem . 这是一个演示问题jsfiddle

I could solve the problem by polling until the element is displayed, but is there a more elegant solution? 我可以通过轮询直到显示元素来解决该问题,但是还有更优雅的解决方案吗?

Use Vue's nextTick to inject the chart, this will guarantee that the DOM is ready to be updated: 使用Vue的nextTick注入图表,这将确保DOM准备更新:

ready: function() {
  this.$nextTick(function() {
        this.chart = new Highcharts.Chart(this.opts);
  });
}

http://jsfiddle.net/crabbly/hje7bqrn/ http://jsfiddle.net/crabbly/hje7bqrn/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM