我试图寻找答案,但没有成功。
window.onload = function() {
console.log(document.getElementById('#sell'));
if(document.getElementById('#sell')){
alert('jo');
//Init for Vue
}
}
它在jQuery中可以运行,但是在纯JS中却不行,为什么?
console.log(document.getElementById('#sell'));
返回结果为NULL
。
jQuery示例:
if ( $( "#sell" ).length ) {
const app = new Vue({
el: '#sell',
components: { sellPicture }
});
}
在我的sell.blade.php文件中,代码如下:
...
<div id="sell">
<sell-picture></sell-picture>
</div>
....
我的脚本被添加到 /body 前
顺便问一下,我需要为 Bootstrap 使用 jQuery,如果我不使用它改变 DOM 的话,在 Vue 中也使用它会有问题吗?
document.getElementById('sell')
,不需要加上井号(#)。 - Stéphane Ammar