// 头部 Vue.component('template-header', { template: `
`, props: { 'header': { type: Object, }, 'page':{ type: Number, } }, data:function () { return { item:this.page, headerObj:this.header } }, created:function () { console.log(this.item) console.log(this.headerObj) }, }) // 底部 Vue.component('template-footer', { template: ``, props: { 'footer': { type: Object, } }, }) Vue.component('template-sidebar', { template: ``, data: function () { return { appearSide: false, scrollTop: 0, } }, props: { 'sidebar': { type: Object } }, mounted() { window.addEventListener('scroll', this.scrollToTop) }, methods: { scrollToTop() {//检测滚动条 this.scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop; // console.log(this.scrollTop) }, goTop: function () { let timer = null, _that = this; cancelAnimationFrame(timer) timer = requestAnimationFrame(function fn() { if (_that.scrollTop > 0) { _that.scrollTop -= 50; document.body.scrollTop = document.documentElement.scrollTop = _that.scrollTop; timer = requestAnimationFrame(fn) } else { cancelAnimationFrame(timer); _that.goTopShow = false; } }) }, closeSidebar: function () { var _this = this if (this.appearSide) { _this.appearSide = !_this.appearSide } else { _this.appearSide = !_this.appearSide } }, hover: function () { this.appearSide = !this.appearSide } }, destroyed() { window.removeEventListener('scroll', this.scrollToTop); } })