vue 动态数字效果 vue-animate-number

安装 vue-animate-number 插件

js 复制代码
npm install vue-animate-number 

(注:是npm、cnpm还是yarn根据具体项目要求)

在 main.js 中引入

js 复制代码
import Vue from 'vue'
import VueAnimateNumber from 'vue-animate-number'
Vue.use(VueAnimateNumber)

动态使用

js 复制代码
<li class="user_Overview-item" style="color: #00fdfa">
    <div class="user_Overview_nums allnum ">
        <!-- <dv-digital-flop :config="config" style="width:100%;height:100%;" /> -->
        <animate-number ref="allnum" :from="config.numberOrigin" :to="config.number" mode="manual"></animate-number>
    </div>
    <p>总设备数</p>
</li>

  data() {
     return {
         config: {
             numberOrigin: 0,
             number: 0
         },
     }
 	}

 getData() {
    currentGET("big2").then((res) => {
        if (res.success) {
            this.$refs.allnum.reset(this.config.number, res.data.totalNum)
            this.$refs.allnum.start()
            this.config = {
                numberOrigin: this.config.number,
                number: res.data.totalNum
            }
        }
    }
}

轮询调用getData,可实现数字的动态设置

js 复制代码
  //轮询
  switper() {
      if (this.timer) {
          return
      }
      let looper = (a) => {
          this.getData()
      };
      this.timer = setInterval(looper, this.$store.state.setting.echartsAutoTime);
  },
相关推荐
灰小猿1 小时前
Spring前后端分离项目时间格式转换问题全局配置解决
java·前端·后端·spring·spring cloud
im_AMBER1 小时前
React 16
前端·笔记·学习·react.js·前端框架
02苏_1 小时前
ES6模板字符串
前端·ecmascript·es6
excel1 小时前
⚙️ 一次性警告机制的实现:warnOnce 源码深度解析
前端
excel1 小时前
Vue SFC 样式编译核心机制详解:compileStyle 与 PostCSS 管线设计
前端
excel1 小时前
🧩 使用 Babel + MagicString 实现动态重写 export default 的通用方案
前端
excel1 小时前
Vue SFC 编译器主导出文件解析:模块组织与设计哲学
前端
excel1 小时前
深度解析:Vue SFC 模板编译器核心实现 (compileTemplate)
前端
excel1 小时前
Vue SFC 解析器源码深度解析:从结构设计到源码映射
前端
excel1 小时前
Vue SFC 编译全景总结:从源文件到运行时组件的完整链路
前端