123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <template>
- <div ref="wrapper">
- <slot></slot>
- </div>
- </template>
- <script type="text/ecmascript-6">
- import BScroll from 'better-scroll'
- export default {
- props: {
- probeType: {
- type: Number,
- default: 3
- },
- click: {
- type: Boolean,
- default: true
- },
- data: {
- type: Array,
- default: null
- },
- listenScroll: {
- type: Boolean,
- default: false
- },
- pullup: {
- type: Boolean,
- default: false
- },
- scrollEnd: {
- type: Boolean,
- default: false
- }
- },
- 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
- })
- if (this.listenScroll) {
- let me = this
- this.scroll.on('scroll', pos => {
- me.$emit('scroll', pos)
- })
- }
- if (this.pullup) {
- this.scroll.on('scrollEnd', () => {
- if (this.scroll.y <= this.scroll.maxScrollY + 50) {
- this.$emit('scrollToEnd')
- }
- })
- }
- if (this.scrollEnd) {
- this.scroll.on('scrollEnd', () => {
- this.$emit('scrollToEnd')
- })
- }
- },
- enable() {
- this.scroll && this.scroll.enable()
- },
- disable() {
- this.scroll && this.scroll.disable()
- },
- 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)
- }
- },
- watch: {
- data() {
- setTimeout(() => {
- this.refresh()
- }, 20)
- }
- }
- }
- </script>
- <style lang="sass" type="text/sass">
- </style>
|