mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Slider): add left-button and right-button slots (#10053)
This commit is contained in:
parent
95b4cad61a
commit
3976d5583d
@ -168,9 +168,11 @@ export default {
|
||||
|
||||
### Slots
|
||||
|
||||
| Name | Description |
|
||||
| ------ | ------------- |
|
||||
| button | Custom button |
|
||||
| Name | Description | Arguments |
|
||||
| ------------ | ------------------------------ | ----------------- |
|
||||
| button | Custom button | - |
|
||||
| left-button | Custom left button (in range) | { value: number } |
|
||||
| right-button | Custom right button (in range) | { value: number } |
|
||||
|
||||
### Less Variables
|
||||
|
||||
|
@ -174,9 +174,11 @@ export default {
|
||||
|
||||
### Slots
|
||||
|
||||
| 名称 | 说明 |
|
||||
| ------ | -------------- |
|
||||
| button | 自定义滑动按钮 |
|
||||
| 名称 | 说明 | 参数 |
|
||||
| ------------ | ---------------------------------- | ----------------- |
|
||||
| button | 自定义滑动按钮 | - |
|
||||
| left-button | 自定义左侧滑块按钮(双滑块模式下) | { value: number } |
|
||||
| right-button | 自定义右侧滑块按钮(双滑块模式下) | { value: number } |
|
||||
|
||||
### 样式变量
|
||||
|
||||
|
@ -44,7 +44,7 @@
|
||||
v-model="value9"
|
||||
range
|
||||
vertical
|
||||
style="margin-left: 100px;"
|
||||
style="margin-left: 100px"
|
||||
@change="onChange"
|
||||
/>
|
||||
</div>
|
||||
|
@ -236,6 +236,7 @@ export default createComponent({
|
||||
const renderButton = (i) => {
|
||||
const map = ['left', 'right'];
|
||||
const isNumber = typeof i === 'number';
|
||||
const current = isNumber ? this.value[i] : this.value
|
||||
const getClassName = () => {
|
||||
if (isNumber) {
|
||||
return `button-wrapper-${map[i]}`;
|
||||
@ -248,6 +249,20 @@ export default createComponent({
|
||||
}
|
||||
return `wrapper`;
|
||||
};
|
||||
const renderButtonContent = () => {
|
||||
if (isNumber) {
|
||||
const slot = this.slots(i === 0 ? 'left-button' : 'right-button', {value: current})
|
||||
if (slot) {
|
||||
return slot
|
||||
}
|
||||
}
|
||||
if (this.slots('button')) {
|
||||
return this.slots('button')
|
||||
}
|
||||
return (
|
||||
<div class={bem('button')} style={this.buttonStyle} />
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -267,9 +282,7 @@ export default createComponent({
|
||||
}}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{this.slots('button') || (
|
||||
<div class={bem('button')} style={this.buttonStyle} />
|
||||
)}
|
||||
{renderButtonContent()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user