string, HTMLElement ,HTMLInputElement - id of html element, input, svg text element, or DOM element reference where counting occurs
endVal
number - 最终数字
options?
object选项对象
options 包含属性
{startVal?: number;// number to start at (0)decimalPlaces?: number;// number of decimal places (0)duration?: number;// animation duration in seconds (2)useGrouping?: boolean;// example: 1,000 vs 1000 (true)useIndianSeparators?: boolean;// example: 1,00,000 vs 100,000 (false)useEasing?: boolean;// ease animation (true)smartEasingThreshold?: number;// smooth easing for large numbers above this if useEasing (999)smartEasingAmount?: number;// amount to be eased for numbers above threshold (333)separator?: string;// grouping separator (',')decimal?: string;// decimal ('.')// easingFn: easing function for animation (easeOutExpo)easingFn?:(t: number,b: number,c: number,d: number)=> number;formattingFn?:(n: number)=> string;// this function formats resultprefix?: string;// text prepended to resultsuffix?: string;// text appended to resultnumerals?: string[];// numeral glyph substitutionenableScrollSpy?: boolean;// start animation when target is in viewscrollSpyDelay?: number;// delay (ms) after target comes into viewscrollSpyOnce?: boolean;// run only onceonCompleteCallback?:()=> any;// gets called when animation completesplugin?: CountUpPlugin;// for alternate animations}
3. Vue组件封装
3.1 组件代码
<template><spanref="count"id="countupId"/></template><script>import{ CountUp }from'countup.js'const defaultOptions ={startVal:0,decimalPlaces:2,duration:1,useGrouping:true,useEasing:true,smartEasingThreshold:999,smartEasingAmount:333,// amount to be eased for numbers above threshold (333)separator:',',decimal:'.',// decimal ('.')}exportdefault{name:'CountUp',props:{// 起始值endVal:{type: Number,default:0},options:{type: Object,default:()=>{}}},watch:{endVal(){if(this.$refs.count){this.initCountUp()}}},mounted(){this.initCountUp()},methods:{initCountUp(){const coutOptions = Object.assign({}, defaultOptions,this.options)const countUp =newCountUp(this.$refs.count,this.endVal, coutOptions)countUp.start()}}}</script>
proxy
一般情况
代码
let data{name:张三,age:12
}
let proxyDatanew Proxy(data,{get(target,key,receiver){console.log(targetdata)console.log(receiverproxyData)console.log(targetreceiver)console.log(target,key,receiver)return target[key]},set(target,key,newV…