- 我是用了uni-app官方提供的顶部选项卡弄的,在swiper中在包含了个swiper在H5运行出现问题,不知道是不是我的方法错了还是。。。直接上代码吧:
- <template>
- <view>
- <view class="navTab">
- <view v-for="(tab,index) in navlist" :key="index" :class="['navTab-list',tabIndex==index ? 'active' : '']"
- data-current="index" @tap="tapTab">
{{tab.name}}
<view class="navTab-bar"></view>
</view>
</view>
<swiper :current="tabIndex" @change="changeTab" style="height: 1200upx;">
<swiper-item>
<scroll-view scroll-y>
<swiper :indicator-dots="true" :interval="3000" :duration="1000" style="width: 750upx;height: 750upx;">
<swiper-item>
<view class="swiper-item">
<image src="../../static/c1.png" mode="aspectFit"></image>
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
<image src="../../static/c2.png" mode="aspectFit"></image>
</view>
</swiper-item>
<swiper-item>
<view class="swiper-item">
<image src="../../static/c3.png" mode="aspectFit"></image>
</view>
</swiper-item>
</swiper>
</scroll-view>
</swiper-item>
<swiper-item>
<scroll-view scroll-y>
详情
</scroll-view>
</swiper-item>
<swiper-item>
<scroll-view scroll-y>
评价
</scroll-view>
</swiper-item>
</swiper>
</view>
</template>
<script>
export default {
data() {
return {
navlist: [{
name: '商品',
id: '1'
}, {
name: '详情',
id: '2'
}, {
name: '评价',
id: '3'
}],
tabIndex: 0,
}
},
onLoad() {
},
methods: {
async changeTab(e) {
console.log(e);
let index = e.target.current;
this.tabIndex = e.target.current; //一旦访问data就会出问题
},
async tapTab(e) { //点击tab-bar
var _index = e.target.dataset.current;
console.log(_index);
if (_index != undefined) {
if (this.tabIndex == _index) {
return false;
} else {
this.tabIndex = Number(_index);
}
}
},
}
}
</script>
<style>
.uni-status-bar {
display: none;
}
.navTab {
width: 93%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: center;
padding: 10upx 0;
box-sizing: border-box;
}
.navTab-list {
padding: 0 20upx;
line-height: 34px;
color: #121212;
}
.navTab-list text {
height: 100%;
display: block;
}
.navTab-bar {
width: 100%;
height: 2px;
background-color: transparent;
}
.navTab-list.active {
color: blue;
}
.navTab-list.active .navTab-bar {
background-color: blue;
}
uni-image{
width: 750upx;
height: 750upx;
}
</style>
quitter (作者)
...没咋用过这个
2018-12-25 15:27