vue项目的一个问题,地址: http://59.110.14.246/
gitee地址:https://gitee.com/xnsky/motion/blob/master/src/views/home/recordDetail.vue
就是一直进入文章详情页然后返回,一直重复,直到重复十几次接近20次的时候,页面开始逐渐卡顿,直到卡死
监听什么的都移除了,找了很久也没找到什么问题
是因为什么问题导致的
created(){
this.pubsub.isExpand = this.$pubsub.subscribe('handleExpand', this.handleExpand)
this.pubsub.comment_list = this.$pubsub.subscribe('getCommentsList', this.getCommentsList)
this.pubsub.cancelReply = this.$pubsub.subscribe('handleCancelReply', this.handleCancelReply)
recordDetail(this.$route.params.id).then(({ result }) => {
result.likeList = JSON.parse(result.likeList)
this.recordDate = result
// 评论列表
this.recordDate?.enableComment && this.getCommentsList()
})
// 随机5文章
randomList(5, this.$route.params.id).then(({ randomArticles }) => {
this.randomArticles = randomArticles
})
// 获取上一篇和下一篇文章
prevArticle(this.$route.params.id).then(({ context }) => {
this.context = context
})
},
mounted() {
this.handleDebounce = debounce(this.handleShowMenu, 200)
window.addEventListener('scroll', this.handleDebounce)
// 用户点击来 10 秒后添加预览人数
this.$nextTick(() => {
this.showTime = setTimeout(() => {
UpDateRecordShowNum(this.$route.params.id)
console.log('qwe');
}, 10000)
})
},
beforeDestroy() {
window.removeEventListener('scroll', this.handleDebounce)
// 离开之前清理定时器
clearTimeout(this.showTime)
this.$pubsub.unsubscribe(this.pubsub.isExpand)
this.$pubsub.unsubscribe(this.pubsub.comment_list)
this.$pubsub.unsubscribe(this.pubsub.cancelReply)
}