uview的Tabs 标签怎么滑动内容切换

uview的Tabs 标签怎么滑动内容切换?现在可以点击tabs切换,现在想要滑动内容切换


<view>
        <u-tabs
                :list="list"
                :is-scroll="false"
                :current="current"
                bar-width="50"
                swipeable 
                active-color="#30B1B7"
                @change="change"
              ></u-tabs>
        <view v-if="current == 0">111</view>
        <view v-if="current == 1">222</view>
        <view v-if="current == 2">333</view>
        <view v-if="current == 3">444</view>
        <view v-if="current == 4">555</view>
        <view v-if="current == 5">666</view>
    </view>
list: [
                    {
                      name: "所有",
                    },
                    {
                      name: "热销",
                    },
                    {
                      name: "球类",
                    },
                    {
                      name: "鞋类",
                    },
                    {
                      name: "分类A",
                    },
                    {
                      name: "分类B",
                    },
                  ],
                current: 0,
change(index) {
                  this.current = index.index;
                  //如报错则用this.current = index代替上行
                },

uview没有配置这个功能,需要自己手动实现
步骤一:将所有的内容容器放进swiper组件中
步骤二:监听swiper的change事件,当前索引改变之后,同步tabs的索引
步骤三:监听tabs组件的change事件,当tabs的索引改变时,同步swiper的索引

你如果想要实现 uView 中的 Tabs 标签滑动内容切换的效果,你可以将 is-scroll 属性设置为 true,使 Tabs 具有滑动功能。此外,你还需要添加一个外层的 Scroll View 包裹 Tabs 和内容部分,以实现滑动切换效果。下面是帮你修改的代码:

<view>
  <scroll-view scroll-x class="tabs-scroll" style="white-space: nowrap;">
    <u-tabs
      :list="list"
      :current="current"
      bar-width="50"
      swipeable 
      active-color="#30B1B7"
      @change="change"
    ></u-tabs>
  </scroll-view>
  
  <scroll-view scroll-y class="content-scroll">
    <view v-if="current == 0">111</view>
    <view v-if="current == 1">222</view>
    <view v-if="current == 2">333</view>
    <view v-if="current == 3">444</view>
    <view v-if="current == 4">555</view>
    <view v-if="current == 5">666</view>
  </scroll-view>
</view>
data() {
  return {
    list: [
      { name: "所有" },
      { name: "热销" },
      { name: "球类" },
      { name: "鞋类" },
      { name: "分类A" },
      { name: "分类B" },
    ],
    current: 0,
  }
},
methods: {
  change(index) {
    this.current = index;
  },
}

我使用了两个 Scroll View,一个用于 Tabs 的水平滚动,一个用于内容的垂直滚动。通过给第一个 Scroll View 加上 scroll-x 类和样式 white-space: nowrap;,使 Tabs 能够横向滚动。同时,为了实现内容的垂直滚动,给第二个 Scroll View 加上 scroll-y 类。