// 核心关键 获取到数据以后调用监听的方法以免页面高度没撑起来
//导致刚进入页面计算不准确带来的定位问题
<template>
<div >
<div :class="isFixed? 's-bottom':'s-bottom s-bottmo-fixed'"> 需要定位的元素<div >
</div>
</template>
<script>
export default {
layout: 'timeline',
name: 'shopping',
data() {
return {
isFixed:false,
}
},
mounted () {//给window添加一个滚动滚动监听事件
window.addEventListener('scroll', this.handleScroll)
},
destroyed () {//离开该页面需要移除这个监听的事件
window.removeEventListener('scroll', this.handleScroll)
},
methods: {
handleScroll () {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
let clientHeight = document.documentElement.clientHeight;
let scrollHeight = document.documentElement.scrollHeight;
if (scrollTop + clientHeight >= (scrollHeight-50)) {
this.isFixed = true
} else {
this.isFixed = false
}
},
// 获取购物车列表
async getCartGoods() {
const params = {
...this.params,
...this.goodsForm
}
let data = await this.$api('mallWeb.cartGoods')(params)
this.goodList = data.dataList;
this.total = data.total
// 核心关键 获取到数据以后调用监听的方法以免页面高度没撑起来
//导致刚进入页面计算不准确带来的定位问题
this.$nextTick(()=>{
this.handleScroll()
})
}
```}