quitter
quitter
  • 发布:2018-12-25 15:25
  • 更新:2018-12-25 16:28
  • 阅读:1491

【报Bug】swiper组件在H5中无法正常滑动

分类:uni-app
我是用了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>

2018-12-25 15:25 负责人:无 分享
已邀请:
回梦無痕

回梦無痕 - 暂停服务

用代码标签框一下代码吧,这样太难看了

  • quitter (作者)

    ...没咋用过这个

    2018-12-25 15:27

quitter

quitter (作者) - 此人很懒,没有留下介绍

<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>  

该问题目前已经被锁定, 无法添加新回复