Vue.js监听页面加载完成后添加业务逻辑

原创
2023/01/30 16:02
阅读数 2.3K
document.onreadystatechange = () => {
  if (document.readyState == "complete") {
    console.log('Page completed with image and files!')
    // fetch to next page or some code
  }
}

注意如果使用Accordion等元素,并且有多个在Vue循环里的话,需要等页面全部加载完成了才能初始化Accordion,不然只有第一个Accordion是生效的,因为页面没加载完全的话循环里的html还没有输出完全,只有模版.vue里的一个是写好的,其他都还没生成,所以需要等页面全部加载完成了,再去初始化Accordion组件才能全部识别到所有循环的元素,我试了上面的方式第一次可以,但页面刷新后又没用了,最后用了下面的updated的方式才最终解决

补充:

 

mounted() {
    window.addEventListener('load', () => {
         // run after everything is in-place
    })
},

// 99% using "mounted()" with the code above is enough, 
// but incase its not, you can also hook into "updated()"
//
// keep in mind that any code in here will re-run on each time the DOM change
updated() {
    // run something after dom has changed by vue
}
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部