Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

Subsection 分段器

该分段器一般用于用户从几个选项中选择某一个的场景

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

  • 通过list数组参数传递分段的选项,数组元素可为字符串,或者通过keyName参数传入对象(默认为name)
  • 通过current指定初始化时激活的选项
html
<template>
	<up-subsection :list="list" :current="1"></up-subsection>
</template>

<script>
	export default {
		data() {
			return {
                list: ['未付款', '待评价', '已付款'],
				// 或者如下,也可以配置keyName参数修改对象键名
				// list: [{name: '未付款'}, {name: '待评价'}, {name: '已付款'}],
				current: 1
			}
		}
	}
</script>

模式选择

通过mode设置分段器的模式

  • 值为button时为按钮类型
  • 值为subsection时为分段器形式
html
<up-subsection :list="list" mode="subsection" :current="1"></up-subsection>

颜色配置

  • 通过activeColor配置激活选项的文字颜色
  • 通过inactiveColor配置未激活选项的文字颜色
  • 通过bgColor配置背景颜色,mode为button时有效(默认 '#eeeeef' )
html
<up-subsection activeColor="#f56c6c"></up-subsection>

注意事项

如果想通过一个变量绑定current值,需要在change事件回调中修改此值,否则可能会由于props的限制,前后两次设置current为相同的值, 而导致无法通过修改current值触发分段器的变化。

html
<template>
    <up-subsection :list="list" :current="curNow" @change="sectionChange"></up-subsection>
</template>

<script>
	export default {
		data() {
			return {
                list: ['未付款', '待评价', '已付款'],
				curNow: 0
			}
		},
		methods: {
			sectionChange(index) {
				this.curNow = index;
			}
		}
	}
</script>

此页面源代码地址

页面源码地址


 github  gitee

API

Props

参数说明类型默认值可选值
list选项的数组,形式见上方"基本使用"Array--
current初始化时默认选中的选项索引值String | Number0-
activeColor激活时的颜色String#3c9cff-
inactiveColor未激活时的颜色String#303133-
mode模式选择,见上方"模式选择"说明Stringbuttonsubsection
fontSize字体大小,单位pxString | Number12-
bold激活选项的字体是否加粗Booleantruefalse
bgColor组件背景颜色,modebutton时有效String#eeeeef-
keyNamelist元素对象中读取的键名Stringname-

Events

事件名说明回调参数
change分段器选项发生改变时触发index:选项的index索引值,从0开始

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发