展示金额动画
moneyAni(money, label = 'money', hasPercent = false, nowMoney = 0, step = 10) {
const vm = this
if (!money) {
vm[label] = '0' + (hasPercent ? '.00' : '')
console.log(vm[label])
return false
}
const moneyStep = 50 * step
const _nowMoney = nowMoney + moneyStep >= money ? money : nowMoney + moneyStep
const m = _nowMoney.toString()
const m0 = m.split('.')
let percent = m0[1] || '00'
percent = percent.length === 1 ? percent + '0' : !percent.length ? '00' : percent
const m1 = percent && hasPercent ? '.' + percent : ''
const _money = m0[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + m1
vm[label] = _money // Filter.priceFilter(money)
setTimeout(() => {
if (_nowMoney < money) {
vm.moneyAni(money, label, hasPercent, _nowMoney, step + 100)
}
}, 1200)
},
调用
1.引入mixin
2.调用方法