better-scroll滑动插件的使用

使用条件 

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()
    }
  })
},

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值