简体   繁体   English

初始化Vue.js时延迟

[英]Delay when initializing Vue.js

I am embedding Vue.js into an existing application. 我将Vue.js嵌入到现有应用程序中。

When initializing Vue.js like so: 像这样初始化Vue.js时:

new Vue({
    el: "#myDomElement",
    data: myData,
    computed: {
        price: function() { 
            return _this.productPrice(); 
        },
    },
    created: function() { console.log("Vue created."); },
    beforeCompile: function() { console.log("Vue about to compile."); },
    compiled: function() { console.log("Vue compiled."); },
    ready: function() { console.log("Vue ready."); },
});

I am getting a lag of about 10 seconds at this point in my code. 此时,我的代码中出现了大约10秒钟的延迟。 After this delay the lifecycle hooks (created, beforeCompile etc.) all fire at once. 在此延迟之后,生命周期钩子(创建的,beforeCompile等)立即全部触发。

The delay is independent of the view, even if myDomElement is an empty div the delay occurs. 延迟与视图无关,即使myDomElement为空div也会发生延迟。

Might be relevant: 可能相关:

  • The myData object is not small but not huge either (28KB when JSON.stringified) myData对象也不小但也不大(JSON.stringified时为28KB)

  • The Vue.js initialization happens in a module, that is exported via modules.export and then wrapped up by Webpack Vue.js初始化发生在一个模块中,该模块通过modules.export导出,然后由Webpack打包

It turned out the data object myData was too complex (and it was significantly larger than stated by me in the original post). 事实证明,数据对象myData太复杂了(它比我在原始帖子中所说的要大得多)。

The Vue.js documentation states Vue.js文档状态

It is not recommended to observe complex objects. 不建议观察复杂的物体。

see Vue.js docs 请参阅Vue.js文档

We were able to move some data of the myData object to another object with no data binding and get the application running smoothly again. 我们能够将myData对象的某些数据移动到另一个没有数据绑定的对象,并使应用程序再次平稳运行。

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

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