33# Segmented 分段器 <el-tag text style =" vertical-align : middle ;margin-left :8px ;" effect =" plain " >0.1.23</el-tag >
44
55## 何时使用
6- * 用于展示多个选项并允许用户选择其中单个选项;
7- * 当切换选中选项时,关联区域的内容会发生变化。
86
7+ - 用于展示多个选项并允许用户选择其中单个选项;
8+ - 当切换选中选项时,关联区域的内容会发生变化。
99
1010## 基本用法
1111
1414``` vue
1515<wd-segmented :options="list" v-model:value="current"></wd-segmented>
1616```
17+
1718``` ts
1819const list = ref <string []>([' 评论' , ' 点赞' , ' 贡献' , ' 打赏' ])
1920
@@ -28,7 +29,6 @@ const current = ref('点赞')
2829<wd-segmented :options =" list" v-model:value =" current" size =" large" ></wd-segmented >
2930```
3031
31-
3232## 小型分段器
3333
3434通过设置 ` size ` 属性为 ` "small" ` ,创建一个小型分段器。
@@ -62,13 +62,12 @@ const current = ref('点赞')
6262 <template #label =" { option }" >
6363 <view class =" section-slot" >
6464 <image style =" border-radius : 50% ; width : 32px ; height : 32px " :src =" option.payload.avatar" />
65- <view class =" name" >
66- {{ option.value }}
67- </view >
65+ <view class =" name" >{{ option.value }}</view >
6866 </view >
6967 </template >
7068</wd-segmented >
7169```
70+
7271``` ts
7372const list = ref ([
7473 {
@@ -87,6 +86,7 @@ const list = ref([
8786 }
8887])
8988```
89+
9090``` scss
9191.section {
9292 width : 100% ;
@@ -96,47 +96,90 @@ const list = ref([
9696 padding : 4px ;
9797 }
9898}
99-
10099```
101100
101+ ## 在弹出框中使用
102+ 微信小程序端,在弹出框中使用本组件时,需要调用 ` updateActiveStyle ` 方法更新分段器样式,参见[ 常见问题] ( /guide/common-problems.html#%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%A8%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E4%B8%8A%E4%BD%BF%E7%94%A8popup%E3%80%81actionsheet%E3%80%81dropdownitem%E7%AD%89%E5%BC%B9%E5%87%BA%E6%A1%86%E7%BB%84%E4%BB%B6%E5%8C%85%E8%A3%B9slider%E3%80%81tabs%E7%AD%89%E7%BB%84%E4%BB%B6%E6%97%B6-slider%E3%80%81tabs%E8%A1%A8%E7%8E%B0%E5%BC%82%E5%B8%B8 ) 。
103+
104+
105+ ``` html
106+ <wd-button @click =" handleClick" >打开弹窗</wd-button >
107+ <wd-popup v-model =" showPopup" position =" bottom" @after-enter =" handlePopupShow" closable custom-style =" height: 200px;padding: 0 24rpx;" >
108+ <view class =" title" >在弹出框中使用</view >
109+ <wd-segmented :options =" list" v-model:value =" current" ref =" segmentedRef" ></wd-segmented >
110+ </wd-popup >
111+ ```
112+ ``` ts
113+ const list = ref <string []>([' 评论' , ' 点赞' , ' 贡献' , ' 打赏' ])
114+ const current = ref (' 点赞' )
102115
116+ const segmentedRef = ref <SegmentedInstance >() // 获取分段器实例
117+ const showPopup = ref (false ) // 控制popup显示
118+ /**
119+ * 点击按钮打开popup
120+ */
121+ function handleClick() {
122+ showPopup .value = true
123+ }
124+ /**
125+ * popup打开后更新分段器样式
126+ */
127+ function handlePopupShow() {
128+ segmentedRef .value ?.updateActiveStyle ()
129+ }
130+ ```
131+ ``` css
132+ .title {
133+ display : flex ;
134+ font-size : 32 rpx;
135+ align-items : center ;
136+ justify-content : center ;
137+ padding : 24 rpx 0 ;
138+ }
139+ ```
103140
104141## Attributes
105142
106- | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
107- | ------------ | ----------------------------- | --------------- | ------ | ------ | -------- |
108- | value/v-model: value | 当前选中的值 | string \| number | - | - | 0.1.23 |
109- | disabled | 是否禁用分段器 | boolean | true \| false | ` false ` | 0.1.23 |
110- | size | 控件尺寸 | string | ` large ` \| ` middle ` \| ` small ` | ` middle ` | 0.1.23 |
111- | options | 数据集合 | ` string[] \| number[] \| SegmentedOption[] ` | - | [ ] | 0.1.23 |
112- | vibrateShort | 切换选项时是否振动 | boolean | true \| false | ` false ` | 0.1.23 |
143+ | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
144+ | ------------------- | ------------------ | ------------------------------------------- | ------------------------------ | -- ------ | -------- |
145+ | value/v-model: value | 当前选中的值 | string \| number | - | - | 0.1.23 |
146+ | disabled | 是否禁用分段器 | boolean | true \| false | ` false ` | 0.1.23 |
147+ | size | 控件尺寸 | string | ` large ` \| ` middle ` \| ` small ` | ` middle ` | 0.1.23 |
148+ | options | 数据集合 | ` string[] \| number[] \| SegmentedOption[] ` | - | [ ] | 0.1.23 |
149+ | vibrateShort | 切换选项时是否振动 | boolean | true \| false | ` false ` | 0.1.23 |
113150
114151### SegmentedOption
115152
116- | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
117- | ---------- | ------------ | ---------------------- | ------ | ------ | -------- |
118- | value | 选中值 | string \| number | - | - | 0.1.23 |
119- | disabled | 是否禁用 | boolean | true \| false | - | 0.1.23 |
120- | payload | 更多数据 | any | - | - | 0.1.23 |
121-
153+ | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
154+ | -------- | -------- | ---------------- | ------------- | ------ | -------- |
155+ | value | 选中值 | string \| number | - | - | 0.1.23 |
156+ | disabled | 是否禁用 | boolean | true \| false | - | 0.1.23 |
157+ | payload | 更多数据 | any | - | - | 0.1.23 |
122158
123159## Events
124160
125- | 事件名称 | 说明 | 参数 | 最低版本 |
126- | -------- | -------------------------- | ----------- | -------- |
127- | change | 选项切换时触发 | ` SegmentedOption ` | 0.1.23 |
128- | click | 选项点击时触发 | ` SegmentedOption ` | 1.2.20 |
161+ | 事件名称 | 说明 | 参数 | 最低版本 |
162+ | -------- | -------------- | ----------------- | -------- |
163+ | change | 选项切换时触发 | ` SegmentedOption ` | 0.1.23 |
164+ | click | 选项点击时触发 | ` SegmentedOption ` | 1.2.20 |
129165
130- ## Slots
166+ ## Methods
167+
168+ 对外暴露函数
131169
132- | name | 说明 | 参数 | 最低版本 |
133- | ------ | -------------------- | ----------------------- | -------- |
134- | label | 选项标签内容 | ` { option: SegmentedOption } ` | 0.1.23 |
170+ | 事件名称 | 说明 | 参数 | 最低版本 |
171+ | ----------------- | --------------------------------------------------------- | ------------------------------ | -------- |
172+ | updateActiveStyle | 更新滑块偏移量,参数` animation ` 用于是否开启动画,默认开启 | ` (animation: boolean) => void ` | - |
173+
174+ ## Slots
135175
176+ | name | 说明 | 参数 | 最低版本 |
177+ | ----- | ------------ | ----------------------------- | -------- |
178+ | label | 选项标签内容 | ` { option: SegmentedOption } ` | 0.1.23 |
136179
137180## 外部样式类
138181
139- | 类名 | 说明 | 最低版本 |
140- | ------------ | ---------- | -------- |
141- | customStyle | 自定义样式 | 0.1.23 |
142- | customClass | 自定义样式类 | 0.1.23 |
182+ | 类名 | 说明 | 最低版本 |
183+ | ----------- | -- ---------- | -------- |
184+ | customStyle | 自定义样式 | 0.1.23 |
185+ | customClass | 自定义样式类 | 0.1.23 |
0 commit comments