1***@163.com
1***@163.com
  • 发布:2022-05-27 09:30
  • 更新:2022-05-27 09:30
  • 阅读:244

v-if中的 $refs 在H5和小程序的表现不一致

分类:uni-app
  1. 页面pages/index/index:

    <view class="content">  
    <view class="tabs">  
      <view class="tab" v-for="(tab, i) in tabs" :key="i" :class="i === index ? 'bg-active' : ''" @click="toTab(i)">{{tab.name}}</view>  
    </view>  
        <swiper :indicator-dots="false" :current="index" @animationfinish="animationfinish" :autoplay="false" class="tab-content">  
          <swiper-item v-for="tab in tabs" :key="tab.name" >  
        <scroll-view scroll-y class="tab-content">  
          <view class="swiper-item" v-if="tab.content">  
            <unicloud-db ref="udb" v-slot:default="{data, loading,hasMore, error, options}" collection="department-user" :where="tab.where" orderby="_id asc">  
              <view v-if="error">{{error.message}}</view>  
              <view v-else>  
                <department v-for="item in data" :key="item._id" :item="item"></department>  
    
                <view v-if="loading">加载中</view>  
                <view v-else-if="hasMore === false">没有更多了</view>  
                <view v-else-if="data.length === 0">没有数据</view>  
              </view>  
            </unicloud-db>  
    
          </view>  
        </scroll-view>  
          </swiper-item>  
        </swiper>  
    </view>
    export default {  
        data() {  
            return {  
                tabs: [  
          {content:false, name: '全部', where: ''},  
          {content:false, name: '餐饮部', where: `department_name == '餐饮部'`},  
          {content:false, name: '服务部', where: `department_name == '服务部'`},  
          {content:false, name: '客房部', where: `department_name == '客房部'`},  
        ],  
        index: 0,  
            }  
        },  
        onLoad(e) {  
      console.log(e);  
      const index = e.index || 0;  
      this.setTab(index);  
        },  
        methods: {  
    
      setTab(index) {  
        this.index = index;  
        const tab = this.tabs[this.index];  
        const firstLoad = tab.content === false;  
        tab.content = true;  
        if(firstLoad) {  
          console.log(`第${this.index + 1}个tab首次加载`);  
          console.log('展示所有udb');  
          this.$nextTick(() => {  
            console.log(this.$refs.udb.map(udb => udb.where));  
          })  
        }  
      },  
    
      animationfinish(e) {  
        this.setTab(e.detail.current)  
      },  
    
      toTab(index) {  
        this.setTab(index)  
      },  
        }  
    }

在h5 谷歌浏览器上的表现

在微信小程序上的表现:

请问 ,出现这种不一致是什么原因呢。。。

2022-05-27 09:30 负责人:无 分享
已邀请:

要回复问题请先登录注册