2016-08-17 19:56:39 +08:00
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value1: null,
|
|
|
|
|
value2: null,
|
|
|
|
|
value3: null,
|
|
|
|
|
value4: null,
|
2016-08-18 15:53:54 +08:00
|
|
|
|
value5: 3.7
|
2016-08-17 19:56:39 +08:00
|
|
|
|
};
|
2016-09-05 15:34:53 +08:00
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
let firstDemo = document.querySelector('.source');
|
|
|
|
|
firstDemo.style.padding = '0';
|
|
|
|
|
});
|
2016-08-17 19:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<style>
|
2016-09-05 15:34:53 +08:00
|
|
|
|
.demo-rate .block {
|
|
|
|
|
padding: 30px 0;
|
|
|
|
|
text-align: center;
|
|
|
|
|
border-right: solid 1px #EFF2F6;
|
2017-09-29 15:37:50 +08:00
|
|
|
|
display: inline-block;
|
2016-11-06 15:37:35 +08:00
|
|
|
|
width: 50%;
|
|
|
|
|
box-sizing: border-box;
|
2016-09-05 15:34:53 +08:00
|
|
|
|
&:last-child {
|
|
|
|
|
border-right: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-23 13:36:07 +08:00
|
|
|
|
|
2016-09-05 15:34:53 +08:00
|
|
|
|
.demo-rate .demonstration {
|
|
|
|
|
display: block;
|
|
|
|
|
color: #8492a6;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
margin-bottom: 20px;
|
2016-08-17 19:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
## Rate 评分
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
评分组件
|
2017-03-23 13:36:07 +08:00
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
### 基础用法
|
|
|
|
|
|
2016-09-05 15:34:53 +08:00
|
|
|
|
:::demo 评分被分为三个等级,可以利用颜色对分数及情感倾向进行分级(默认情况下不区分颜色)。三个等级所对应的颜色用过`colors`属性设置,而它们对应的两个阈值则通过 `low-threshold` 和 `high-threshold` 设定。
|
2016-08-17 19:56:39 +08:00
|
|
|
|
``` html
|
2016-09-05 15:34:53 +08:00
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">默认不区分颜色</span>
|
|
|
|
|
<el-rate v-model="value1"></el-rate>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="block">
|
|
|
|
|
<span class="demonstration">区分颜色</span>
|
|
|
|
|
<el-rate
|
|
|
|
|
v-model="value2"
|
|
|
|
|
:colors="['#99A9BF', '#F7BA2A', '#FF9900']">
|
|
|
|
|
</el-rate>
|
|
|
|
|
</div>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value1: null,
|
|
|
|
|
value2: null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-08-17 19:56:39 +08:00
|
|
|
|
```
|
2016-08-27 16:06:22 +08:00
|
|
|
|
:::
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-29 10:53:00 +08:00
|
|
|
|
### 辅助文字
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
用辅助文字直接地表达对应分数
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
:::demo 为组件设置 `show-text` 属性会在右侧显示辅助文字。通过设置 `texts` 可以为每一个分值指定对应的辅助文字。`texts` 为一个数组,长度应等于最大值 `max`。
|
2016-08-17 19:56:39 +08:00
|
|
|
|
``` html
|
2016-08-27 16:06:22 +08:00
|
|
|
|
<el-rate
|
|
|
|
|
v-model="value3"
|
|
|
|
|
show-text>
|
|
|
|
|
</el-rate>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value3: null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-08-17 19:56:39 +08:00
|
|
|
|
```
|
2016-08-27 16:06:22 +08:00
|
|
|
|
:::
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-09-05 15:34:53 +08:00
|
|
|
|
### 其它 icon
|
|
|
|
|
|
|
|
|
|
当有多层评价时,可以用不同类型的 icon 区分评分层级
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-09-05 15:34:53 +08:00
|
|
|
|
:::demo 设置`icon-classes`属性可以自定义对应 3 个不同分段的图标。本例还使用`void-icon-class`指定了未选中时的图标类名。
|
2016-08-17 19:56:39 +08:00
|
|
|
|
``` html
|
2016-08-18 15:53:54 +08:00
|
|
|
|
<el-rate
|
|
|
|
|
v-model="value4"
|
|
|
|
|
:icon-classes="['icon-rate-face-1', 'icon-rate-face-2', 'icon-rate-face-3']"
|
|
|
|
|
void-icon-class="icon-rate-face-off"
|
|
|
|
|
:colors="['#99A9BF', '#F7BA2A', '#FF9900']">
|
|
|
|
|
</el-rate>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value4: null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-08-17 19:56:39 +08:00
|
|
|
|
```
|
2016-08-27 16:06:22 +08:00
|
|
|
|
:::
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-29 10:53:00 +08:00
|
|
|
|
### 只读
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-27 16:06:22 +08:00
|
|
|
|
只读的评分用来展示分数,允许出现半星
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2017-08-04 14:57:44 +08:00
|
|
|
|
:::demo 为组件设置 `disabled` 属性表示组件为只读,支持小数分值。此时若设置 `show-score`,则会在右侧显示目前的分值。可以提供 `score-template` 作为显示模板,模板为一个包含了 `{value}` 的字符串,`{value}` 会被解析为分值。
|
2016-08-17 19:56:39 +08:00
|
|
|
|
``` html
|
2016-08-27 16:06:22 +08:00
|
|
|
|
<el-rate
|
|
|
|
|
v-model="value5"
|
|
|
|
|
disabled
|
2017-08-04 14:57:44 +08:00
|
|
|
|
show-score
|
2016-08-27 16:06:22 +08:00
|
|
|
|
text-color="#ff9900"
|
2017-08-04 14:57:44 +08:00
|
|
|
|
score-template="{value}">
|
2016-08-27 16:06:22 +08:00
|
|
|
|
</el-rate>
|
2016-11-14 18:10:52 +08:00
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
value5: 3.7
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2016-08-17 19:56:39 +08:00
|
|
|
|
```
|
2016-08-27 16:06:22 +08:00
|
|
|
|
:::
|
|
|
|
|
|
2016-08-29 10:53:00 +08:00
|
|
|
|
### Attributes
|
2016-08-17 19:56:39 +08:00
|
|
|
|
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
|
|
|
|
|---------- |-------- |---------- |------------- |-------- |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| max | 最大分值 | number | — | 5 |
|
|
|
|
|
| disabled | 是否为只读 | boolean | — | false |
|
|
|
|
|
| allow-half | 是否允许半选 | boolean | — | false |
|
2016-12-13 22:52:29 +08:00
|
|
|
|
| low-threshold | 低分和中等分数的界限值,值本身被划分在低分中 | number | — | 2 |
|
|
|
|
|
| high-threshold | 高分和中等分数的界限值,值本身被划分在高分中 | number | — | 4 |
|
|
|
|
|
| colors | icon 的颜色数组,共有 3 个元素,为 3 个分段所对应的颜色 | array | — | ['#F7BA2A', '#F7BA2A', '#F7BA2A'] |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| void-color | 未选中 icon 的颜色 | string | — | #C6D1DE |
|
|
|
|
|
| disabled-void-color | 只读时未选中 icon 的颜色 | string | — | #EFF2F7 |
|
2016-12-13 22:52:29 +08:00
|
|
|
|
| icon-classes | icon 的类名数组,共有 3 个元素,为 3 个分段所对应的类名 | array | — | ['el-icon-star-on', 'el-icon-star-on','el-icon-star-on'] |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| void-icon-class | 未选中 icon 的类名 | string | — | el-icon-star-off |
|
|
|
|
|
| disabled-void-icon-class | 只读时未选中 icon 的类名 | string | — | el-icon-star-on |
|
2017-08-04 14:57:44 +08:00
|
|
|
|
| show-text | 是否显示辅助文字,若为真,则会从 texts 数组中选取当前分数对应的文字内容 | boolean | — | false |
|
|
|
|
|
| show-score | 是否显示当前分数,show-score 和 show-text 不能同时为真 | boolean | — | false |
|
2017-03-23 13:36:07 +08:00
|
|
|
|
| text-color | 辅助文字的颜色 | string | — | #1F2D3D |
|
2016-09-02 13:56:47 +08:00
|
|
|
|
| texts | 辅助文字数组 | array | — | ['极差', '失望', '一般', '满意', '惊喜'] |
|
2017-08-04 14:57:44 +08:00
|
|
|
|
| score-template | 分数显示模板 | string | — | {value} |
|
2016-08-17 19:56:39 +08:00
|
|
|
|
|
2016-08-29 10:53:00 +08:00
|
|
|
|
### Events
|
2016-08-17 19:56:39 +08:00
|
|
|
|
| 事件名称 | 说明 | 回调参数 |
|
|
|
|
|
|---------- |-------- |---------- |
|
|
|
|
|
| change | 分值改变时触发 | 改变后的分值 |
|
|
|
|
|
|