diff --git a/examples/docs/en-US/slider.md b/examples/docs/en-US/slider.md
index 8f3c8a8aa..1d3c29cd2 100644
--- a/examples/docs/en-US/slider.md
+++ b/examples/docs/en-US/slider.md
@@ -5,12 +5,18 @@
value1: 0,
value2: 50,
value3: 36,
- value4: 42,
- value5: 0,
+ value4: 48,
+ value5: 42,
value6: 0,
value7: 0,
- value8: [4, 8]
+ value8: 0,
+ value9: [4, 8]
};
+ },
+ methods: {
+ formatTooltip(val) {
+ return val / 100;
+ }
}
}
@@ -39,9 +45,13 @@ The current value is displayed when the slider is being dragged.
Hide Tooltip
+
+ Format Tooltip
+
+
Disabled
-
+
@@ -52,7 +62,13 @@ The current value is displayed when the slider is being dragged.
value1: 0,
value2: 50,
value3: 36,
- value4: 42
+ value4: 48,
+ value5: 42
+ }
+ },
+ methods: {
+ formatTooltip(val) {
+ return val / 100;
}
}
}
@@ -71,14 +87,14 @@ The options can be discrete.
Breakpoints not displayed
Breakpoints displayed
@@ -89,8 +105,8 @@ The options can be discrete.
export default {
data() {
return {
- value5: 0,
- value6: 0
+ value6: 0,
+ value7: 0
}
}
}
@@ -108,7 +124,7 @@ Set value via a input box.
@@ -118,7 +134,7 @@ Set value via a input box.
export default {
data() {
return {
- value7: 0
+ value8: 0
}
}
}
@@ -135,7 +151,7 @@ Selecting a range of values is supported.
@@ -147,7 +163,7 @@ Selecting a range of values is supported.
export default {
data() {
return {
- value8: [4, 8]
+ value9: [4, 8]
}
}
}
@@ -166,6 +182,7 @@ Selecting a range of values is supported.
| show-input-controls | whether to display control buttons when `show-input` is true | boolean | — | true |
| show-stops | whether to display breakpoints | boolean | — | false |
| show-tooltip | whether to display tooltip value | boolean | — | true |
+| format-tooltip | format to display tooltip value | Function(value) | — | — |
| range | whether to select a range | boolean | — | false |
## Events
diff --git a/examples/docs/zh-CN/slider.md b/examples/docs/zh-CN/slider.md
index 251c6242e..99af558b5 100644
--- a/examples/docs/zh-CN/slider.md
+++ b/examples/docs/zh-CN/slider.md
@@ -5,12 +5,18 @@
value1: 0,
value2: 50,
value3: 36,
- value4: 42,
- value5: 0,
+ value4: 48,
+ value5: 42,
value6: 0,
value7: 0,
- value8: [4, 8]
+ value8: 0,
+ value9: [4, 8]
};
+ },
+ methods: {
+ formatTooltip(val) {
+ return val / 100;
+ }
}
}
@@ -65,9 +71,13 @@
隐藏 Tooltip
+
+ 格式化 Tooltip
+
+
禁用
-
+
@@ -78,7 +88,13 @@
value1: 0,
value2: 50,
value3: 36,
- value4: 42
+ value4: 48,
+ value5: 42
+ }
+ },
+ methods: {
+ formatTooltip(val) {
+ return val / 100;
}
}
}
@@ -96,14 +112,14 @@
不显示间断点
显示间断点
@@ -114,8 +130,8 @@
export default {
data() {
return {
- value5: 0,
- value6: 0
+ value6: 0,
+ value7: 0
}
}
}
@@ -132,7 +148,7 @@
@@ -142,7 +158,7 @@
export default {
data() {
return {
- value7: 0
+ value8: 0
}
}
}
@@ -159,7 +175,7 @@
@@ -171,7 +187,7 @@
export default {
data() {
return {
- value8: [4, 8]
+ value9: [4, 8]
}
}
}
@@ -190,6 +206,7 @@
| show-input-controls | 在显示输入框的情况下,是否显示输入框的控制按钮 | boolean | — | true|
| show-stops | 是否显示间断点 | boolean | — | false |
| show-tooltip | 是否显示 tooltip | boolean | — | true |
+| format-tooltip | 格式化 tooltip message | Function(value) | — | — |
| range | 是否为范围选择 | boolean | — | false |
### Events
diff --git a/packages/slider/src/button.vue b/packages/slider/src/button.vue
index 601463929..8bc54653f 100644
--- a/packages/slider/src/button.vue
+++ b/packages/slider/src/button.vue
@@ -8,7 +8,7 @@
:style="{ left: currentPosition }"
ref="button">
- {{ value }}
+ {{ formatValue }}
@@ -70,6 +70,14 @@
currentPosition() {
return `${ (this.value - this.min) / (this.max - this.min) * 100 }%`;
+ },
+
+ enableFormat() {
+ return this.$parent.formatTooltip instanceof Function;
+ },
+
+ formatValue() {
+ return this.enableFormat && this.$parent.formatTooltip(this.value) || this.value;
}
},
@@ -159,4 +167,3 @@
}
};
-
diff --git a/packages/slider/src/main.vue b/packages/slider/src/main.vue
index f3565591a..92f950f36 100644
--- a/packages/slider/src/main.vue
+++ b/packages/slider/src/main.vue
@@ -83,6 +83,7 @@
type: Boolean,
default: true
},
+ formatTooltip: Function,
disabled: {
type: Boolean,
default: false
diff --git a/test/unit/specs/slider.spec.js b/test/unit/specs/slider.spec.js
index 412af8ae7..fc965d9f2 100644
--- a/test/unit/specs/slider.spec.js
+++ b/test/unit/specs/slider.spec.js
@@ -81,6 +81,33 @@ describe('Slider', () => {
expect(slider.$refs.tooltip.disabled).to.true;
});
+ it('format tooltip', () => {
+ vm = createVue({
+ template: `
+
+
+
+
+ `,
+
+ data() {
+ return {
+ value: 0
+ };
+ },
+ methods: {
+ formatTooltip(val) {
+ return '$' + val;
+ }
+ }
+ }, true);
+ const slider = vm.$children[0].$children[0];
+ expect(slider.formatTooltip).to.function;
+ vm.$nextTick(() => {
+ expect(slider.formatValue).to.equal('$0');
+ });
+ });
+
it('drag', done => {
vm = createVue({
template: `