Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

使用vue怎么在所有元素加载完后执行?

我发现不用jquery(document).ready()不行:

<script>
Vue.componue('test',{...});
new Vue().$mount("#t");
</script>
<div id="t">
    <test></test>
</div>

上面代码并没有产生效果.

<script>
    jQuery(document).ready(function(){
        Vue.componue('test',{...});
        new Vue().$mount("#t");
    });
    
</script>
<div id="t">
    <test></test>
</div>

这样才可以。可是这肯定不合理,因为vue不可能一定要依赖jquery。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

script 标签放到挂载的目标元素后面就可以了:

<div id="t">
    <test></test>
</div>
<script>
    Vue.componue('test',{...});
    new Vue().$mount("#t"); 
</script>

脚本后置还可以缩短首屏渲染时间。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...