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 92 93 94 95 96 97
| import BScroll from 'better-scroll'
export default { props: { probeType: { type: Number, default: 1 }, click: { type: Boolean, default: true }, scrollX: { type: Boolean, default: false }, scrollY: { type: Boolean, default: false }, bounce: { type: Boolean, default: false }, autoBlur: { type: Boolean, default: false }, pullup: { type: Boolean, default: false }, pulldown: { type: Boolean, default: false }, listenScroll: { type: Boolean, default: false }, data: { type: Array, default: null }, beforeScroll: { type: Boolean, default: false }, refreshDelay: { type: Number, default: 20 }, showIcon: { type: Boolean, default: true }, toTop: { type: Boolean, default: false } ... }, methods: { _initScroll() { if (!this.$refs.wrapper) { return } this.scroll = new BScroll(this.$refs.wrapper, { probeType: this.probeType, click: this.click,up scrollX: this.scrollX, pullup: this.pullup, pulldown: this.pulldown })
if (this.listenScroll) { this.scroll.on('scroll', (pos) => { if (pos.y > 120) { this.pullDownMsg = '释放后进行刷新' } }) } this.scroll.on('pullingDown', () => { this.$emit('pulldown') setTimeout(() => { this.scroll.finishPullDown() this.scroll.refresh() this.pullDownMsg = '-下拉刷新-' }, 600) })
if (this.beforeScroll) { this.scroll.on('beforeScrollStart', () => { this.$emit('beforeScroll') }) } }, disable() { this.scroll && this.scroll.disable() }, enable() { this.scroll && this.scroll.enable() }, refresh() { this.scroll && this.scroll.refresh() }, scrollTo() { this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments) }, scrollToElement() { this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments) }, }, mounted() { setTimeout(() => { this._initScroll() }, this.refreshDelay) }, watch: { data() { setTimeout(() => { this.refresh() }, this.refreshDelay) }, }, }
|