zoukankan      html  css  js  c++  java
  • uniapp 滑动导航组件封装

    <template>
        <view>
            <scroll-view scroll-x class="scroll-view_H">
                <!-- <view class="scrollbox"> -->
                <block v-for="(item,index) in menuList">
                    <view :class="{'currentline':active==index}" @click="tabtap(index)">{{item}}</view>
                </block>
                <!-- </view> -->
            </scroll-view>
        </view>
    </template>
    
    <script>
        export default{
            props:{
                menuList:Array,
                active:Number
            },
            methods:{
                tabtap(index){
                    this.$emit('tabtap',index)
                }
            }
        }
    </script>
    
    <style scoped lang="scss">
        .scroll-view_H {
            /* 文本不会换行,文本会在在同一行上继续,直到遇到 <br> 标签为止。 */
            white-space: nowrap;
             100%;
        
            view {
                display: inline-block;
                margin: 40rpx;
                font-size: 26rpx;
        
            }
        }
        
        .currentline {
            color: #000;
            font-weight: bold;
            position: relative;
        }
        
        .currentline::before {
            position: absolute;
            height: 4px;
             100%;
            background-color: #fede33;
            border-radius: 4px;
            content: "";
            left: 0;
            bottom: 0;
            z-index: -1;
        }
    </style>

    上面组件文件   scrollmenu.vue

    引用scrollmenu.vue的首页文件

    <template>
        <view>
            <scroll-tab :menuList="menuList" :active="active" @tabtap="tabtap" />
        </view>
    </template>
    <script>
        import scrollTab from "../../mycomponents/scrollmenu.vue"
        export default {
            data() {
                return {
                    active: 0,
                    menuList: [
                        "关注",
                        "推荐",
                        "体育",
                        "热点",
                        "推荐",
                        "体育",
                        "热点",
                        "财经"
                    ]
                }
            },
            methods: {
                tabtap(index) {
                    this.active = index
                }
            },
            components: {
                scrollTab
            }
        }
    </script>

    组件使用三步骤

    引用组件   import scrollTab from "../../mycomponents/scrollmenu.vue"

    注册组件   components: { scrollTab }

    组件传值    <scroll-tab :menuList="menuList" :active="active" @tabtap="tabtap" />

    效果图

  • 相关阅读:
    Linux的命令、用户、权限管理
    Java中快捷键
    数组的学习
    Java中方法定义和调用的学习
    java中的标识符、修饰符、关键字
    MYSQL的学习
    JavaScript小白教程2
    navicat中选择utf-8时的困惑
    python小白教程
    英语单词
  • 原文地址:https://www.cnblogs.com/ddqyc/p/13769332.html
Copyright © 2011-2022 走看看