2018-04-01 11:23:56 +00:00
|
|
|
<cn>
|
|
|
|
#### 带 icon 的滑块
|
|
|
|
滑块左右可以设置图标来表达业务含义。
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
|
|
|
#### Slider with icon
|
|
|
|
You can add an icon beside the slider to make it meaningful.
|
|
|
|
</us>
|
|
|
|
|
|
|
|
```html
|
|
|
|
<template>
|
|
|
|
<div class="icon-wrapper">
|
|
|
|
<a-icon :style="{color: preColor}" type="frown-o" />
|
|
|
|
<a-slider :min="0" :max="20" @change="handleChange" :value="value" />
|
|
|
|
<a-slider :min="0" :max="20" v-model="value" />
|
|
|
|
<a-icon :style="{color: nextColor}" type="smile-o" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-09-28 12:45:07 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
value: 0,
|
|
|
|
min: 0,
|
|
|
|
max: 20,
|
|
|
|
};
|
2018-04-01 11:23:56 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
methods: {
|
|
|
|
handleChange(value) {
|
|
|
|
this.value = value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
preColor() {
|
|
|
|
const { max, min, value } = this;
|
|
|
|
const mid = ((max - min) / 2).toFixed(5);
|
|
|
|
return value >= mid ? '' : 'rgba(0, 0, 0, .45)';
|
|
|
|
const nextColor = value >= mid ? 'rgba(0, 0, 0, .45)' : '';
|
|
|
|
},
|
|
|
|
nextColor() {
|
|
|
|
const { max, min, value } = this;
|
|
|
|
const mid = ((max - min) / 2).toFixed(5);
|
|
|
|
return value >= mid ? 'rgba(0, 0, 0, .45)' : '';
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2018-04-01 11:23:56 +00:00
|
|
|
</script>
|
|
|
|
<style scoped>
|
2019-09-28 12:45:07 +00:00
|
|
|
.icon-wrapper {
|
|
|
|
position: relative;
|
|
|
|
padding: 0px 30px;
|
|
|
|
}
|
2018-04-01 11:23:56 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
.icon-wrapper .anticon {
|
|
|
|
position: absolute;
|
|
|
|
top: -2px;
|
|
|
|
width: 16px;
|
|
|
|
height: 16px;
|
|
|
|
line-height: 1;
|
|
|
|
font-size: 16px;
|
|
|
|
color: rgba(0, 0, 0, 0.25);
|
|
|
|
}
|
2018-04-01 11:23:56 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
.icon-wrapper .anticon:first-child {
|
|
|
|
left: 0;
|
|
|
|
}
|
2018-04-01 11:23:56 +00:00
|
|
|
|
2019-09-28 12:45:07 +00:00
|
|
|
.icon-wrapper .anticon:last-child {
|
|
|
|
right: 0;
|
|
|
|
}
|
2018-04-01 11:23:56 +00:00
|
|
|
</style>
|
|
|
|
```
|