[英]Run vue component only if element loaded
I have a small vue.js component defined on a javascript. 我在javascript上定义了一个小的vue.js组件。
Is any elegant way to instance the vue component only when the element is loaded? 是否只有在加载元素时才能优雅地实例化vue组件?
The issue is I am receiving these warnings in other htmls where the element is not present: 问题是我在没有元素的其他html中收到这些警告:
vue.js:485 [Vue warn]: Cannot find element: #item
Because it's running this js everywhere 因为它在任何地方都运行此js
new Vue({
el: '#item',
});
How is it taken care of in vue.js? 在vue.js中如何处理?
Test for the element before creating the instance. 在创建实例之前测试元素。
if(document.getElementById("#item")){
new Vue({
el: '#item',
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.