Vue.js 来自其他路由的方法影响当前路由
我必须查看两个路由器-Vue.js 来自其他路由的方法影响当前路由,vue.js,vue-router,Vue.js,Vue Router,我必须查看两个路由器-Home.vue和List.vue。主页是索引,列表是另一页 我从主页导航到列表页面,然后我有一个显示10个项目的方法 scrolled() { var self = this var pageHeight = document.documentElement.offsetHeight, windowHeight = window.innerHeight, scrollPosition = win
Home.vue
和List.vue
。主页是索引,列表是另一页
我从主页导航到列表页面,然后我有一个显示10个项目的方法
scrolled() {
var self = this
var pageHeight = document.documentElement.offsetHeight,
windowHeight = window.innerHeight,
scrollPosition =
window.scrollY
|| window.pageYOffset
|| document.body.scrollTop + (document
.documentElement && document.documentElement.scrollTop || 0);
if (pageHeight <= windowHeight + scrollPosition) {
// code to display data
self.currentPage = self.currentPage + 1
self.getGameHistory(self.currentPage)
}
}
scrolled(){
var self=这个
var pageHeight=document.documentElement.offsetHeight,
windowHeight=window.innerHeight,
滚动位置=
窗口滚动
||window.pageYOffset
||document.body.scrollTop+(文档
.documentElement&&document.documentElement.scrollTop | | 0);
如果(pageHeight假设,您正在使用mounted()
生命周期方法在window
对象上使用滚动事件侦听器,您必须在window
对象上注销全局事件侦听器:
const opts = {
mounted() {
window.addEventListener('scroll', this.scrolled);
},
beforeDestroy() {
// UN-REGISTER THE GLOBAL HANDLER BEFORE COMPONENT IS DESTROYED
window.removeEventListener('scroll', this.scrolled);
},
method: {
scrolled() {
/* Your Logic */
}
}
};
您需要为我们显示一些代码来帮助…添加一个代码片段来显示如何将滚动的方法注册到窗口对象。