日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

基于vue2.0以及better-scroll实现scroll滑动组件及所实现组件的应用例子

發布時間:2023/12/31 vue 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于vue2.0以及better-scroll实现scroll滑动组件及所实现组件的应用例子 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

直接上源碼:

組件:scroll.vue,需要先npm install better-scroll

<template><div ref="wrapper"><slot></slot></div> </template><script type="text/ecmascript-6">import BScroll from 'better-scroll'const DIRECTION_H = 'horizontal'const DIRECTION_V = 'vertical'export default {props: {probeType: {type: Number,default: 1},click: {type: Boolean,default: false},listenScroll: {type: Boolean,default: false},data: {type: Array,default: null},pullup: {type: Boolean,default: false},beforeScroll: {type: Boolean,default: false},refreshDelay: {type: Number,default: 20},direction: {type: String,default: DIRECTION_V}},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,eventPassthrough: this.direction === DIRECTION_V ? DIRECTION_H : DIRECTION_V})if (this.listenScroll) {this.scroll.on('scroll', (pos) => {this.$emit('scroll', pos)})}if (this.pullup) {this.scroll.on('scrollEnd', () => {if (this.scroll.y <= (this.scroll.maxScrollY + 50)) {this.$emit('scrollToEnd')}})}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)}},watch: {data() {setTimeout(() => {this.refresh()}, this.refreshDelay)}}} </script><style scoped lang="stylus" rel="stylesheet/stylus"></style>
應用方法:

引入并注冊組件:

import Scroll from 'base/scroll/scroll'export default {components: {Scroll}}
template結構以及style:



效果:圖中輪播圖+列表為滾動區域(recommend-content),即需要滾動的內容;對應的class:slider為輪播圖,recommend-list為列表。由于輪播圖數據以及list數據為動態獲取,實際使用請填充你的數據,以上只給出關鍵結構。



已實現滾動:




總結

以上是生活随笔為你收集整理的基于vue2.0以及better-scroll实现scroll滑动组件及所实现组件的应用例子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。