请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

better-scroll 2.0.4版本,给内部标签添加点击事件,会执行两次

正在回答 回答被采纳积分+3

插入代码

2回答

提问者 Hecocacola 2020-09-27 17:34:14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 页面
<template>
  <div class="avtive-center">
    <scroll class="active-content" :data="activeList">
      <div>
        <div class="banner" @click="to">
          <img src="../assets/images/active-banner.png" alt="" />
        </div>
        <div class="active-center-lists">
          <template v-for="(item, index) in activeList">
            <active-list :activeList="item" :key="index"></active-list>
          </template>
        </div>
      </div>
    </scroll>
  </div>
</template>
 
 
 
 
// scroll 组件
<template>
  <div ref="wrapper">
    <slot></slot>
  </div>
</template>
 
<script>
import BScroll from "better-scroll";
 
export default {
  props: {
    probeType: {
      type: Number,
      default: 1,
    },
    click: {
      type: Boolean,
      default: true,
    },
    data: {
      type: Array,
      default: [],
    },
    refreshDelay: {
      type: Number,
      default: 20,
    },
  },
  watch: {
    data() {
      setTimeout(() => {
        this._initScroll();
      }, this.refreshDelay);
    },
  },
  mounted() {
    setTimeout(() => {
      this._initScroll();
    }, 20);
  },
  methods: {
    _initScroll() {
      if (!this.$refs.wrapper) {
        return;
      }
      this.scroll = new BScroll(this.$refs.wrapper, {
        probeType: this.probeType,
        click: this.click,
        scrollX: true,
      });
    },
 
    enable() {
      // 如果这个this.scroll 是有的,就调用this.scroll.enable()
      this.scroll && this.scroll.enable();
    },
 
    disable() {
      this.scroll && this.scroll.disable();
    },
 
    refresh() {
      this.scroll && this.scroll.refresh();
    },
  },
};
</script>
 
<style lang="less" scoped></style>



0 回复 有任何疑惑可以回复我~
ustbhuangyi 2020-09-27 17:18:48

套了 2 层 scroll 吗

0 回复 有任何疑惑可以回复我~
  • 提问者 Hecocacola #1
    一层,这个是在工作项目用的,然后又去试了下音乐项目排行榜列表,也是执行两次
    回复 有任何疑惑可以回复我~ 2020-09-27 17:20:46
  • 提问者 Hecocacola #2
    八月学的时候安装版本是1.15.2,现在安装的是2.0.4
    回复 有任何疑惑可以回复我~ 2020-09-27 17:23:40
  • ustbhuangyi 回复 提问者 Hecocacola #3
    提供一下可以复现问题的 repo,我抽空帮你看看
    回复 有任何疑惑可以回复我~ 2020-09-27 17:25:17
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号