123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <template>
- <refresh @refresh="refresh" @pullingdown="onpullingdown" :display="showRefresh ? 'show' : 'hide'">
- <view class="refreshBox">
- <!-- 可以自己添加图片路径或base64实现图片 <image class="refreshImg" :src="config[state].img" mode="widthFix" resize="cover"></image> -->
- <text class="refreshText">{{config[state].text}}</text>
- </view>
- </refresh>
- </template>
- <script>
- export default {
- data() {
- return {
- showRefresh:false, // 是否显示刷新
- state:0 // 刷新状态,0:继续下拉执行刷新,1:释放立即刷新,2:正在加载中,3:加载成功
- }
- },
- methods:{
- // 下拉刷新回调函数
- onpullingdown({pullingDistance,viewHeight}) {
- if(pullingDistance < viewHeight){
- this.state = 0 // 继续下拉执行刷新
- }else{
- this.state = 1 // 释放立即刷新
- }
- },
- // 执行刷新
- refresh(){
- // console.log('refresh');
- this.showRefresh = true // 显示刷新
- this.state = 2 // 正在加载中
- this.$emit('refresh') // 触发refresh事件
- }
- },
- watch: {
- // 监听loading变化
- loading(loading, oldValue) {
- if(!loading){
- this.showRefresh = false // 隐藏刷新
- this.state = 3 // 加载成功
- }
- }
- },
- props: {
- loading: {
- type:Boolean,
- default(){
- return false
- }
- },
- config: {
- type: Array,
- default(){
- return [
- {
- text:"继续下拉执行刷新",
- img:""//可以自己添加图片路径或base64实现图片
- },
- {
- text:"释放立即刷新",
- img:""//可以自己添加图片路径或base64实现图片
- },
- {
- text:"正在加载中",
- img:""//可以自己添加图片路径或base64实现图片
- },
- {
- text:"加载成功",
- img:""//可以自己添加图片路径或base64实现图片
- }
- ]
- }
- },
- },
- }
- </script>
- <style lang="scss" scoped>
- .refreshBox{
- width: 750rpx;
- height: 50px;
- justify-content: center;
- align-items: center;
- flex-direction: row;
- /* #ifndef APP-PLUS */
- margin-top: -50px;
- /* #endif */
- }
- .refreshImg{
- width: 55rpx;
- height: 55rpx;
- z-index: 111;
- }
- .refreshText{
- font-size: 26rpx;
- color: #999999;
- padding-left: 6rpx;
- }
- </style>
|