使用条件
1父容器有固定的高度 2 内容过多会溢出,使用了overflow:hidden 3直接给父元素添加使用
使用
1 下载
npm install better-scroll --save
2 引入
import BScroll from 'better-scroll'
3创建实例对象,传入获取到父元素的标签 ,放在函数中
methods: { initScroll () { const menuScroll = new BScroll(this.$refs.menuWrapper) const foodsScroll = new BScroll(this.$refs.foodsWrapper) } }
4因为是异步的操作 在页面更新之后 在调用
mounted () { this.$store.dispatch('getGoods', () => { // setTimeout(() => { // this.initScroll() // },10) this.$nextTick(() => { this.initScroll() }) }) },5 在调用action的方法 的时候要把回调当做参数 传入 用来 通知 调用者 goods组件是否有数据
getGoods({commit}, cb) { // 发送ajax请求, 获取goods数据 reqGoods().then(response => { const result = response.data if(result.code===RESULT_OK) { const goods = result.data // 提交mutaion请求 commit(RECEIVE_GOODS, {goods}) cb && cb() } }) },