微信小程序mina框架12.2-自定义组件-标题激活选中

编辑自定义组件文件 

https://www.bilibili.com/video/BV1nE41117BQ?p=38&spm_id_from=pageDriver

tabs.wxml文件

<view  wx:for="{{tabs}}"  wx:key="id"  class="title_item {{item.isActive?'active':''}} " >        {{item.name}}        </view>

这里用到了微信的循环wx:for 以及三元判断 {{item.isActive?'active':''}} 来对应 tab.js文件tab数组中的    isActive: false   属性

复制代码
<view class="tabs">
    <view class="tabs_title">
        <!-- <view class="title_item">首页</view>
        <view class="title_item">原创</view>
        <view class="title_item">分类</view>
        <view class="title_item">关于</view> -->
        <view 
        wx:for="{{tabs}}" 
        wx:key="id"
        class="title_item {{item.isActive?'active':''}}" 
        
        >
        {{item.name}}
        </view>
    </view>
    <view class="tab_content">内容</view>   

</view>
复制代码

 

tabs.js文件

复制代码
// components/Tabs/Tabs.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        tabs: [
            {
                id: 0,
                name: "首页",
                isActive: true,
            },
            {
                id: 1,
                name: "原创",
                isActive: false,
            },
            {
                id: 2,
                name: "分类",
                isActive: false,
            },
            {
                id: 3,
                name: "关于",
                isActive: false,
            },
        ],
    },

    /**
     * 组件的方法列表
     */
    methods: {},
});
复制代码

 

 

tabs.wxss文件

复制代码
.tabs {
}
.tabs_title {
    display: flex;
    padding: 10rpx 0;
}
.title_item {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}
.active {
    color: red;
    border-bottom: 5rpx solid currentColor;
}
.tab_content {
}
复制代码

 

posted @   茶叶蛋蛋  阅读(110)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示