当前位置: 首页 > 工具软件 > t-scroll > 使用案例 >

Better-Scroll在Vue中报错

黄宏大
2023-12-01
mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      probeType: this.probeType,
      pullUpLoad: this.pullUpLoad,
      click: true
    }),
    this.scroll.on('pullingUp', () => {
      this.$emit('pullingUp')
    }),
    this.scroll.on('scroll', (position) => {
      this.$emit('scrolling', position)
    })
  },
  methods: {
    scrollTo(x, y, time = 500) {
       this.scroll.scrollTo(x, y, time)
    },
    finishPullUp() {
       this.scroll.finishPullUp()
    }

如果在mounted之前回调scroll的方法时,会显示scroll为undefined,这时最好在判断this.scroll是否存在再执行

  methods: {
    scrollTo(x, y, time = 500) {
       this.scroll && this.scroll.scrollTo(x, y, time)
    },
    finishPullUp() {
       this.scroll && this.scroll.finishPullUp()
    }
 类似资料: