我有一些 vue 2 組件:
<template>
<section class="component" v-if="load">
...
</section>
<div class="loader" v-else>
...
</div>
</template>
<script>
export default {
name: "myApp",
data() {
return {
load: false,
}
},
mounted() {
this.initApp();
},
methods: {
initApp() {
this.load = true;
}
}
}
</script>
我像這樣初始化它(很少使用jquery)
if ($('#container').length > 0) {
new Vue({
components: {
myApp
},
render: (h) => {
return h(myApp);
},
}).$mount('#container');
}
另外我在其他非 vue 代碼中有全域檔案的自定義事件,由 jquery 觸發:
$(document).trigger('someEvent');
如何在myApp組件中處理此檔案的someEvent以完全重新加載它?(此事件需要完全更新 myApp 中的內容和資料。)
uj5u.com熱心網友回復:
你試過掛鉤嗎
mounted(){
document.addEventListener("someEvent", ()=>{
//your code after listening to the event
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/346169.html
標籤:javascript 查询 Vue.js dom dom事件
下一篇:為什么控制臺給我結果未定義
