首页 > 编程语言 >#yyds干货盘点#【愚公系列】2022年12月 微信小程序-纵向和横向选项卡功能实现

#yyds干货盘点#【愚公系列】2022年12月 微信小程序-纵向和横向选项卡功能实现

时间:2022-12-10 23:32:38浏览次数:124  
标签:yyds 12 选项卡 String index 微信 no tab vtabs

前言

纵向选项卡(vtabs)用于让用户在不同的视图中进行切换。

以下讲解的是weui版,相关的还有antd-mini版本:https://help.aliyun.com/document_detail/438087.html 在这里插入图片描述

一、纵向选项卡(weui版)

vtabs

属性名 类型 默认值 必选 描述
vtabs Array [] yes 数据项格式为{title}
active-tab Number no 激活选项卡索引
tab-bar-class String no 选项卡样式
active-class String no 行为样式
tab-bar-line-color String #ff0000 no 选定项目带下划线的一面的颜色
tab-inactive-text-color String #000000 no 未选中的字体颜色
tab-bar-active-text-color String #ff0000 no 检查字体颜色
tab-inactive-bg-color String #eeeeee no 未选中的背景色
tab-active-bg-color String #ffffff no 检查背景颜色
animation Boolean true no 打开动画
Bindtablick eventhandle no 触发时点击选项卡,e.detail={index}
bindchange eventhandle no 内容区域滚动原因选项卡更改时触发,以及.detail={index}

vtab-content

属性名 类型 默认值 必选 描述
tab-index Number yes vtabs 数据索引(基于 0)

1.安装包

npm i @miniprogram-component-plus/vtabs
npm i @miniprogram-component-plus/vtabs-content 

2.使用

引用组件

"usingComponents": {
  "mp-vtabs": "@miniprogram-component-plus/vtabs/index",
  "mp-vtabs-content": "@miniprogram-component-plus/vtabs-content/index"
}
Page({
  data: {
    vtabs: [],
    activeTab: 0,
  },

  onl oad() {
    const titles = ['热搜推荐', '手机数码', '家用电器',
      '生鲜果蔬', '酒水饮料', '生活美食', 
      '美妆护肤', '个护清洁', '女装内衣', 
      '男装内衣', '鞋靴箱包', '运动户外', 
      '生活充值', '母婴童装', '玩具乐器', 
      '家居建材', '计生情趣', '医药保健', 
      '时尚钟表', '珠宝饰品', '礼品鲜花', 
      '图书音像', '房产', '电脑办公']
    const vtabs = titles.map(item => ({title: item}))
    this.setData({vtabs})
  },

  onTabCLick(e) {
    const index = e.detail.index
    console.log('tabClick', index)
  },

  onChange(e) {
    const index = e.detail.index
    console.log('change', index)
  }

})

<mp-vtabs 
  vtabs="{{vtabs}}" 
  activeTab="{{activeTab}}" 
  bindtabclick="onTabCLick"
  bindchange="onChange"
  class="test"
>
  <block wx:for="{{vtabs}}" wx:key="title" >
    <mp-vtabs-content tabIndex="{{index}}">
      <view class="vtabs-content-item">我是第{{index + 1}}项: {{item.title}}</view>
    </mp-vtabs-content>
  </block>
</mp-vtabs>
.vtabs-content-item {
    width: 100%;
    height: 300px;
    box-sizing: border-box;
    border-bottom: 1px solid #ccc;
    padding-bottom: 20px;
}

在这里插入图片描述

二、横向选项卡(weui版)

属性名 类型 默认值 必选 描述
tabs Array [] yes 数据项格式为{title}
tab-class String no 选项卡样式
swiper-class String no 内容区域刷卡器样式
active-class String no 行为样式
tab-underline-color String #07c160 no 所选项目的下划线颜色
tab-active-text-color String #000000 no 检查字体颜色
tab-inactive-text-color String #000000 no 未选中的字体颜色
tab-background-color String #ffffff no 选项卡背景色
active-tab Number no 激活选项卡索引
duration Number 500 no 内容区交接持续时间
Bindtablick eventhandle no 触发时点击选项卡,e.detail={index}
bindchange eventhandle no 内容区域滚动原因选项卡更改时触发,以及.detail={index}

1.安装包

npm install @ miniprogram-component-plus/tabs

2.使用

引用组件

"usingComponents": {
  "mp-tabs": "@miniprogram-component-plus/tabs/index"
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 1,
    arr:['1','2','3','4'],
    tabs: [],
    arr2: [],
    activeTab: 0,
  },
  onl oad() {
    const titles = ['首页', '外卖', '商超生鲜', '购物', '美食饮品', '生活服务', '休闲娱乐', '出行']
    const tabs = titles.map(item => ({ title: item }))
    this.setData({ tabs })
    this.setData({ arr2: ['11', '22', '33', '44'] })
  },

  onTabCLick(e) {
    const index = e.detail.index
    console.log('----------'+index);
    this.setData({ activeTab: index })
  },

  onChange(e) {
    const index = e.detail.index
    console.log('----------'+index);
    this.setData({ activeTab: index })
  }
})


 <mp-tabs 
  tabs="{{tabs}}" 
  activeTab="{{activeTab}}" 
  swiperClass="weui-tabs-swiper"
  bindtabclick="onTabCLick"
  bindchange="onChange"
  activeClass="tab-bar-title__selected"
>

  <block wx:for="{{tabs}}" wx:key="title">
    <view class="tab-content" slot="tab-content-{{index}}" > {{item.title}} </view>
  </block>

</mp-tabs>


.bgView {
  /* background-color: orange; */
  height: 500px;
  width: 100%;
}

.bg {
  /* background: red; */
  /* position: fixed;
  top: 0;
  height: 40px; */
}

page {
  height: 100%;
}

/* ------------ weui -------------- */
.weui-tabs-bar__wrp {
  border-bottom: 1px solid #eee;
  position: fixed;
  top: 0;
  height: 30px; 
  z-index:9999;
}

.weui-tabs-swiper {
  margin-top: 30px;
  width: 100%;
  height: 500px;
}

.tab-content {
  width: 100%;
  height: 500px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  /* padding: 40rpx; */
}

.weui-tabs-bar__title {
  margin: 0px 10px;
}

.tab-bar-title__selected {
  font-size: 20px;
  font-weight: bold;
}

在这里插入图片描述

标签:yyds,12,选项卡,String,index,微信,no,tab,vtabs
From: https://blog.51cto.com/u_15437432/5927885

相关文章

  • #yyds干货盘点# LeetCode程序员面试金典:链表求和
    题目:给定两个用链表表示的整数,每个节点包含一个数位。这些数位是反向存放的,也就是个位排在链表首部。编写函数对这两个整数求和,并用链表形式返回结果。 示例:输入:(7->1->......
  • 算法12:LeetCode_二叉树的最大深度
    给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。说明: 叶子节点是指没有子节点的节点。示例:给定二叉树[3,9,20,null,null,......
  • #yyds干货盘点#公司发不出工资,程序员该如何做?
    疫情三年,整体大环境下行,许多公司遇到了问题。最近之前待过的一家公司就出现了问题,从国庆到现在没有发工资,他问我怎么办。公司现金流不稳定,等着客户回款,这种情况下发70%的工......
  • sft1200插件安装|ssr|istore
    之前都是使用代理软件上网,github都得挂(github访问非常玄学)后来买了xbox,发现xbox上有Netflix,所以最终选择软路由,挑来挑去最终咸鱼130收了这个路由器,比r2s便宜还带wifi,主要......
  • 2022-12-10
    天天睡觉不是目标时间入睡,(希望在11点前入睡)躺床上难得入睡.今天早上6点起来穿好衣服,又躺下了.躺了两次,不过今天提前半个小时来教室了.看了下视频.好像没什么......
  • 12-主动连接之socketChannel
    新入门skynet系列视频b站网址https://www.bilibili.com/video/BV19d4y1678X主动连接之socketChannel当我们打算主动跟外部通讯时,我们一般使用socketchannel。socke......
  • P1248 加工生产调度&P2123 皇后游戏
    P1248加工生产调度P2123皇后游戏Johnson法则早就该会了……一般地,设\(c_i\)表示完成第\(i\)个后的时间,得\[c_i=\begin{cases}a_1+b_1&(i=1)\\\max\left(c_......
  • js之操作文件| 12-5
    在HTML表单中,可以上传文件的唯一控件就是​​<inputtype="file">​​。注意:当一个表单包含​​<inputtype="file">​​时,表单的​​enctype​​必须指定为​​multipart/f......
  • 在微信上搭建ChatGpt机器人
    在微信上搭建ChatGpt机器人项目地址:https://gitee.com/shtml/wechatbot?_from=gitee_search准备一个服务器:Windos,Centos,Ubuntu环境:Go()一个微信号用作机器人一个Ope......
  • [2022-12-06]神经网络与深度学习hw11 - 各种优化算法比较
    OverridetheentrypointofanimageIntroducedinGitLabandGitLabRunner9.4.Readmoreaboutthe extendedconfigurationoptions.Beforeexplainingtheav......