美文网首页
uni-app简单选项卡,商品分类

uni-app简单选项卡,商品分类

作者: 吃肉肉不吃肉肉 | 来源:发表于2020-12-08 16:02 被阅读0次

    实现一个简单选项卡,通过查找下标,动态绑定一个class
    方法一:

    <template>
            <view>
                    <view class="inv-h-w">
                            <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="Inv=0">选项卡1</view>
                            <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="Inv=1">我是选项卡二</view>
                    </view>
                    <view class="" v-show="Inv == 0">
                            我是选项卡一
                    </view>
                    <view class="" v-show="Inv == 1">
                            我是选项卡二
                    </view>
            </view>
    </template>
     
    <script>
            export default {
                    data() {
                            return {
                                    Inv:0
                            }
                    },
                    methods: {
                          
                    }
            }
    </script>
             
    <style>
            .inv-h-w{background-color: #FFFFFF;height: 100upx;display: flex;}
            .inv-h{font-size: 30upx;flex: 1;text-align: center;color: #C9C9C9;height: 100upx;line-height: 100upx;}
            .inv-h-se{color: #5BA7FF;border-bottom: 4upx solid #5BA7FF;}
            page{background-color: #F2F2F2;}
    </style>
    

    方法二:

    <template>
            <view>
                   <view class="end-title">
                     <view v-for="(item,index) in items" :key="index" :class="{btna:count == index}" @tap="change(index)">
                        {{item}}
                     </view>
                </view>
                    <view class="end-cont" :class="{dis:btnnum == 0}">0信息</view>
                    <view class="end-cont" :class="{dis:btnnum == 1}">1信息</view>
                    <view class="end-cont" :class="{dis:btnnum == 2}">2信息</view>
            </view>
    </template>
     
    <script>
            export default {
                    data() {
                            return {
                                   btnnum: 0,
                                    items:["基本信息","公告信息","换区信息"],
                                   count:"",
                            }
                    },
                    methods: {
                          change(e) {
                            this.count = e
                            this.btnnum = e
                            console.log(this.count)
                        }
                    }
            }
    </script>
             
    <style>
        .end-title{
            display: flex;
        }
        .end-title view{
            flex-grow: 1;
            text-align: center;
        }
        .end-cont{
            display: none;
            background: #C8C7CC;
        }
        .btna{
            color: #FFFFFF;
            background: #00A0FF;
        }
        .dis{
            display: block;
        }
    </style>
    

    常见商品分类布局
    效果:

    image.png
    代码如下:
    <template>
        <view style="background-color: #FFFFFF;">
            <view class="navBar">
                <view class="navBar-search">
                        <image src="../../static/search.png" mode="widthFix" style="width: 34rpx;"></image>
                        <input type="text" v-model="search" confirm-type="search" @confirm="getSearch" placeholder="华为P30 Pro" placeholder-style="font-size:30rpx;color:#B5B9BF"/>
                </view>
            </view>
            <view class="flex-content">
                <view class="end-title">
                     <view v-for="(item,index) in items" :key="index" :class="{btna:count == index}" @tap="change(index)">
                        {{item}}
                     </view>
                </view>
                <view class="end-cont">
                        <image src="../../static/fenlei1.png" mode="widthFix" style="width: 530rpx"></image>
                        <view class="title">{{goodsList.titleOne}}</view>
                        <view class="goods">
                            <view class="goods-item" v-for="(item,index) in goodsList.goods" :key="index">
                                <image :src="item.imageUrl" mode="widthFix" style="width: 90rpx;"></image>
                                <text>{{item.name}}</text>
                            </view>
                        </view>
                </view>
            </view>
            
        </view>
    </template>
    <script>
        export default{
            data() {
               return {
                  btnnum: 0,
                  items:["精选推荐","华为手机","荣耀手机","笔记本","平板电脑","智能穿戴"],
                  count:"",
                  search:"",
                  goodsList:{},
                
              };
            },
            onShow() {
                this.goodsList=this.data[0]
            },
            methods:{
              change(e) {
                 this.count = e
                 this.btnnum = e
                 this.goodsList=this.data[e]//这里data是获取到的右侧商品数据
                 console.log(this.goodsList)
                 // console.log(this.count)
              },
              scroll(){},
              getSearch(){}
            }
        }
    </script>
    
    <style lang="scss" scoped>
        .navBar{
            padding:5rpx 32rpx 6rpx 28rpx;
            height: 80rpx;
            display: flex;
            align-items: center;
            &-search{
                margin: 0 auto;
                width: 690rpx;
                height:58rpx;
                background-color: #F8F9FA;
                border-radius:30rpx;
                padding-left: 16rpx;
                // margin-right: 32rpx;
                display: flex;
                justify-content: flex-start;
                align-items: center;
                input{
                    margin-left: 20rpx;
                }
            }
        }
        .flex-content{
            display: flex;
        }
        .end-title{
            display:flex;
            flex-direction: column;
            width: 180rpx;
            background-color: #F3F5F7;
            view{
                height: 185rpx;
                line-height: 185rpx;
                text-align: center;
                font-size:26rpx;
                font-weight: bold;
                color: #4E5152;
                border-bottom: 1rpx solid #ECEDEE;
                border-left: 8rpx solid #F3F5F7;
            }
            .btna{
                color:#FF6C5C;
                background-color:#FFFFFF;
                border-left: 8rpx solid #FF6C5C;
                }
        }
        /* .end-title view{flex-grow:1;text-align:center;} */
        .end-cont{
            width: 550rpx;
            // display:none;
            // padding:20rpx 22rpx 0 22rpx ;
            .title{
                font-size: 30rpx;
                font-weight: bold;
                text-align: center;
                color:#4E5152;
            }
            .goods{
                // font-size: 10rpx;
                width: 100%;
                display: flex;
                justify-content:space-around;
                flex-wrap: wrap;
                // flex-wrap: nowrap;
                &-item{
                    width: 150rpx;
                    // height: 180rpx;
                    border: 1rpx solid #3B4144;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    flex-direction: column;
                    text{
                        font-size: 20rpx;
                        width: 90rpx;
                        // display: -webkit-box;
                        // -webkit-box-orient: vertical; 
                        //  text-overflow: ellipsis;
                        // -webkit-line-clamp: 2;
                        // overflow: hidden;
                    }
                }
            }
            image{
                margin: 20rpx 0 60rpx 20rpx;
            }
        }
        
        .dis{display:block;}
    </style>
    

    相关文章

      网友评论

          本文标题:uni-app简单选项卡,商品分类

          本文链接:https://www.haomeiwen.com/subject/bftqgktx.html