账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue里countup一直报错是什么原因?
    38
    0

    上代码:

    <template>
        <span :class="commonClass" :style="commonStyle">
            <span :class="selfClass" :style="selfStyle" :id="countId">{{ initCount }}</span>
        </span>
    </template>
    
    <script>
    import CountUp from 'countup'
    export default {
        data () {
            return {
                count: {},
                countId: 'count' + parseInt(Math.random() * 1000000)
            }
        },
        props: {
            // 公用的class
            commonClass: {
                type: String,
                default: ''
            },
            // 公用的style
            commonStyle: {
                type: Object,
                default: () => {
                    return {
                        fontSize: '30px',
                        color: '#dc9387'
                    }
                }
            },
            // 私有的class
            selfClass: {
                type: String,
                default: ''
            },
            // 私有的style
            selfStyle: {
                type: Object
            },
            // 初始的默认值
            initCount: {
                type: Number,
                default: 0
            },
            // 旧值
            oldValue: {
                type: Number,
                default: 0
            },
            // 新值
            newValue: {
                type: Number,
                default: 0
            },
            // 保留小数位数
            decimals: {
                type: Number,
                default: 0
            },
            // 完整动画过渡的时间,单位秒
            duration: {
                type: Number,
                default: 2
            },
            // 是否线性过渡变化,false为是
            useEasing: {
                type: Boolean,
                default: false
            },
            // 是否每三位数字用符号标识
            useGrouping: {
                type: Boolean,
                default: true
            },
            // 标识的符号
            separator: {
                type: String,
                default: ','
            },
            // 小数的符号
            decimal: {
                type: String,
                default: ','
            },
            // 前置展示的文字
            prefix: {
                type: String,
                default: ''
            },
            // 后置展示的文字
            suffix: {
                type: String,
                default: ''
            },
            // 延迟开始过渡动画时间,单位毫秒
            delay: {
                type: Number,
                default: 0
            }
        },
        methods: {
        },
        mounted () {
            this.$nextTick(() => {
                setTimeout(() => {
                    this.count = new CountUp(this.countId, this.oldValue, this.newValue, this.decimals, this.duration, {
                        useEasing: this.useEasing,
                        useGrouping: this.useGrouping,
                        separator: this.separator,
                        decimal: this.decimal,
                        prefix: this.prefix,
                        suffix: this.suffix
                    });
                    if (!this.count.error) {
                        this.count.start();
                    } else {
                      console.error(this.count.error);
                    }
                }, this.delay)
            })
        },
        watch: {
            'newValue' (val) {
                this.count.update(val)
            }
        }
    }
    </script>

    打开页面数据展示倒是没什么问题,但是一直报错Error in callback for watcher "newValue": "TypeError: this.count.update is not a function"
    这是为什么?
    另:现在要做的效果是一个接口返回所有数据复用几次这个组件,然后有各自的延迟,但是我这么写实际测了下只有第一次是有延迟的,等到第二次调接口返回数据,所有歌计数都同时开始改变了,这该怎么写?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 单身久了会习惯 普通会员 1楼

      在Vue中,countup插件报错可能有以下几种原因:

      1. 考虑到您的Vue项目使用了浏览器的<script>标签和<style>标签,这些标签之间需要有一个闭合的标签来允许JavaScript执行。如果在<script>标签或<style>标签中使用了其他标签,可能需要调整它们之间的闭合标签。

      2. 如果countup插件的版本不兼容您的Vue项目,或者您的Vue项目在某些情况下运行不正常,也可能导致countup插件报错。您可以尝试更新countup插件到最新版本,或者检查您的Vue项目是否满足countup插件的使用条件。

      3. 如果您在使用countup插件时遇到了其他问题,如报错信息没有详细说明,或者错误信息不明确,建议您查阅countup插件的官方文档,或者联系插件的开发者以获取更多的帮助。

      4. 如果您在使用countup插件时遇到了错误,您可以尝试禁用插件并重新安装,或者尝试使用其他计时器插件来替代countup插件。

      希望以上信息对您有所帮助,如果您还有其他问题,欢迎随时向我提问。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部