[新增] rate 评分组件

This commit is contained in:
就眠仪式 2021-10-08 15:42:14 +08:00
parent e05acc8879
commit e55fdade0e
4 changed files with 81 additions and 54 deletions

View File

@ -131,45 +131,3 @@ export default {
} }
</script> </script>
::: :::
::: demo
<template>
<ul class="site-doc-bgcolor">
<li class="layui-bg-red">
赤色class="layui-bg-red"
</li>
<li class="layui-bg-orange">
橙色class="layui-bg-orange"
</li>
<li class="layui-bg-green">
墨绿class="layui-bg-green"
</li>
<li class="layui-bg-cyan">
藏青class="layui-bg-cyan"
</li>
<li class="layui-bg-blue">
蓝色class="layui-bg-blue"
</li>
<li class="layui-bg-black">
雅黑class="layui-bg-black"
</li>
<li class="layui-bg-gray">
银灰class="layui-bg-gray"
</li>
</ul>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
return {
}
}
}
</script>
:::

View File

@ -17,3 +17,49 @@ export default {
</script> </script>
::: :::
::: demo
<template>
<lay-rate v-model="all"></lay-rate> {{all}}
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const all = ref(4)
return {
all
}
}
}
</script>
:::
::: demo
<template>
<lay-rate v-model="all2" length="10"></lay-rate> {{all2}}
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const all2 = ref(4)
return {
all2
}
}
}
</script>
:::

View File

@ -1,6 +1,6 @@
{ {
"name": "@layui/layui-vue", "name": "@layui/layui-vue",
"version": "0.0.13", "version": "0.0.14",
"description": "a component library for Vue 3 base on layui-vue", "description": "a component library for Vue 3 base on layui-vue",
"main": "lib/layui-vue.umd.js", "main": "lib/layui-vue.umd.js",
"module": "lib/layui-vue.es.js", "module": "lib/layui-vue.es.js",

View File

@ -1,20 +1,19 @@
<template> <template>
<ul class="layui-rate"> <ul class="layui-rate">
<li class="layui-inline"> <li
<i class="layui-icon layui-icon-rate-solid"></i> class="layui-inline"
@mouseenter="mouseenter(index)"
v-for="(rate, index) in rates"
:key="rate"
>
<i class="layui-icon" :class="[rate]"></i>
</li> </li>
<li class="layui-inline">
<i class="layui-icon layui-icon-rate-solid"></i>
</li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
<li class="layui-inline"><i class="layui-icon layui-icon-rate"></i></li>
</ul> </ul>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps, ref, withDefaults } from 'vue' import { defineProps, Ref, ref, withDefaults } from 'vue'
const rate = ref([]) const rates: Ref<Array<String>> = ref([])
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@ -23,7 +22,31 @@ const props = withDefaults(
}>(), }>(),
{ {
length: 5, length: 5,
modelValue: 0 modelValue: 0,
} }
) )
for (let index = 0; index < props.length; index++) {
rates.value.push('layui-icon-rate')
}
for (let index = props.modelValue - 1; index >= 0; index--) {
rates.value[index] = 'layui-icon-rate-solid'
}
const emit = defineEmits(['update:modelValue'])
const mouseenter = function (index: number) {
for (let i = index; i >= 0; i--) {
rates.value[i] = 'layui-icon-rate-solid'
}
for (let j = index + 1; j < props.length; j++) {
rates.value[j] = 'layui-icon-rate'
}
// select update , change
emit('update:modelValue', index+1)
}
</script> </script>