Skip to content

Rate 评分

type : 'rate'

用于对事物进行评级操作。

代码演示

基础用法

<template>
    <div class="">
        <x-form ref="formRef" :model="formValue" :items="formOptions" />
        <div style="margin:10px">
            <van-button @click="onSubmit" block type="primary">验证</van-button>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
const formRef = ref();
const formValue = ref<Indexable>({
    rate1: 3,
    rate2:3.5
});
const formOptions = ref([
     {
        type: 'rate',
        label: '评分',
        name: 'rate1',
        required: true,
        
    },
    {
        type: 'rate',
        label: '评分',
        name: 'rate2',
        required: true,
        attrs: {
            'allow-half': true,
            gutter: 30,
            count: 6
        }
    },
]);

const onSubmit = () => {
    formRef.value?.validate().then(() => {
        console.log('submit values =', formValue.value);
    }).catch((error: any) => {
        console.log('error', error);
    })
}
</script>
<style lang="scss" scoped></style>
基础用法

API

Props

与官方组件 Rate 评分 参数保持一致,这里以展示新增属性配置为主,具体配置参见官方文档。

Events