uni-app滑动切换页面

<template>
  <view class="big">
    <view class="trade">
			<block v-for="(item, index) in tabBars" :key="item.id">
				<view class="texts" :class="curr == index ? 'active' : ''" :data-index="index" @click="setCurr">
					{{item.name}}
				</view>
			</block>
    </view>
    <swiper style="height: 100vh" :current="curr" @change="setCurr">
			<block v-for="item in tabBars" :key="item.id">
				 <swiper-item>
					<scroll-view> {{item.name}} </scroll-view>
				</swiper-item>
			</block>
    </swiper>
  </view>
</template>
<script>
export default {
  data() {
    return {
      curr: 0,
			tabBars: [
        { name: "关注", id: "guanzhu" },
        { name: "推荐", id: "tuijian" },
        { name: "体育", id: "tiyu" },
        { name: "热点", id: "redian" },
        { name: "财经", id: "caijing" },
        { name: "娱乐", id: "yule" },
      ],
    };
  },
  methods: {
    setCurr(e) {
			console.log(1111);
			// console.log(e);
      // console.log(e.detail.current, e.currentTarget.dataset.index);
      let thisCurr = e.detail.current || e.currentTarget.dataset.index || 0;
      // console.log(thisCurr)
      this.curr = thisCurr;
    },
  },
};
// https://www.cnblogs.com/zhoulifeng/p/11613430.html
</script>

<style lang='less' scoped>
.trade {
  width: 100%;
  color: #007aff;
  overflow: auto;
	// display: ;
}
.trade view {
	padding: 20rpx;
	// width: 30rpx;
  text-align: center;
  // padding-left: 25upx;
  // width: 30%;
  float: left;
}
.trade .texts.active {
  border-bottom: 8upx solid #f0ad4e;
}
</style>

参考文章: https://blog.csdn.net/lliter/article/details/103694547?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值