vue 数字滚动count-to插件,支持小数(包含vue3,网上整理)

40 篇文章 3 订阅
20 篇文章 6 订阅

vue3

npm install vue3-count-to --save
<count-to :startVal="0" :endVal="3000.22" :decimals="2" :duration="3000"></count-to>

import { CountTo } from 'vue3-count-to';

components: {
        CountTo
	},

参考地址:https://github.com/xiaofan9/vue-count-to

vue2

npm install vue-count-to
<template>
  <countTo :startVal='startVal' :endVal='endVal' :duration='3000'></countTo>
</template>

<script>
  import countTo from 'vue-count-to';
  export default {
    components: { countTo },
    data () {
      return {
        startVal: 0,
        endVal: 2017
      }
    }
  }
</script>

参考地址: https://github.com/PanJiaChen/vue-countTo

参数说明

PropertyDescriptiontypedefault
startVal开始值Number0
endVal结束值Number2017
duration持续时间,以毫秒为单位Number3000
autoplay自动播放Booleantrue
decimals要显示的小数位数Number0
decimal十进制分割String.
separator分隔符String,
prefix前缀String''
suffix后缀String''
useEasing使用缓和功能Booleantrue
easingFn缓和回调Function

Function NameDescription
mountedCallback挂载以后返回回调
start开始计数
pause暂停计数
reset

重置countTo

  • 3
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是基于Vue3+Ts版本的配置化表单基础组件的实现方式: 1. 在组件中引入表单配置项和表单数据对象: ```vue <template> <el-form :model="formData" :rules="rules" ref="form" label-width="100px"> <el-row :gutter="20"> <el-col :span="item.span" v-for="(item, index) in formConfig" :key="index"> <component :is="item.type" :config="item" :formData="formData"></component> </el-col> </el-row> </el-form> </template> <script> import { defineComponent, ref } from 'vue'; import { ElForm, ElRow, ElCol } from 'element-plus'; import { FormConfig, FormData } from './types'; import FormItem from './FormItem.vue'; export default defineComponent({ name: 'ConfigForm', components: { ElForm, ElRow, ElCol, FormItem, }, props: { formConfig: { type: Array as () => FormConfig[], required: true, }, formData: { type: Object as () => FormData, required: true, }, rules: { type: Object, default: () => ({}), }, }, }); </script> ``` 2. 在表单配置项中定义每个表单项的类型、名称、校验规则等信息: ```vue <script lang="ts"> import { defineComponent } from 'vue'; import { FormItemConfig } from './types'; import { ElInput, ElSelect } from 'element-plus'; export default defineComponent({ name: 'FormItem', components: { ElInput, ElSelect, }, props: { config: { type: Object as () => FormItemConfig, required: true, }, formData: { type: Object, required: true, }, }, computed: { isSelect() { return this.config.type === 'select'; }, }, methods: { handleChange(value: any) { this.$emit('change', value); }, }, }); </script> ``` 3. 在表单项组件中根据表单配置项的类型渲染不同的表单项: ```vue <template> <component :is="isSelect ? 'el-select' : 'el-input'" v-model="formData[config.name]" :placeholder="config.placeholder" :disabled="config.disabled" :options="config.options" @change="handleChange"></component> </template> ``` 4. 在父组件中使用表单组件并传入表单配置项和表单数据对象: ```vue <template> <config-form :form-config="formConfig" :form-data="formData" :rules="rules"></config-form> </template> <script lang="ts"> import { defineComponent, ref } from 'vue'; import ConfigForm from './ConfigForm.vue'; import { FormConfig, FormData } from './types'; export default defineComponent({ name: 'App', components: { ConfigForm, }, setup() { const formData = ref({ name: '', age: '', gender: '', }); const formConfig: FormConfig[] = [ { type: 'input', name: 'name', label: '姓名', placeholder: '请输入姓名', span: 8, rules: [{ required: true, message: '请输入姓名', trigger: 'blur' }], }, { type: 'input', name: 'age', label: '年龄', placeholder: '请输入年龄', span: 8, rules: [{ required: true, message: '请输入年龄', trigger: 'blur' }], }, { type: 'select', name: 'gender', label: '性别', placeholder: '请选择性别', span: 8, options: [ { label: '男', value: 'male' }, { label: '女', value: 'female' }, ], rules: [{ required: true, message: '请选择性别', trigger: 'change' }], }, ]; const rules = { name: [{ required: true, message: '请输入姓名', trigger: 'blur' }], age: [{ required: true, message: '请输入年龄', trigger: 'blur' }], gender: [{ required: true, message: '请选择性别', trigger: 'change' }], }; return { formData, formConfig, rules, }; }, }); </script> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余温无痕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值