Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue.js渲染函数错误 #2

Open
dunizb opened this issue Nov 22, 2017 · 0 comments
Open

Vue.js渲染函数错误 #2

dunizb opened this issue Nov 22, 2017 · 0 comments

Comments

@dunizb
Copy link

dunizb commented Nov 22, 2017

😡 错误描述

在页面{{xxxx.toLocalString()}}的时候Vue显示如下警告:

Error in render function: "TypeError: Cannot read property 'toLocaleString' of undefined"

后改为过滤器方式{{xxxx | convertNum}}

filters: {
    convertNum (val) {
        return val.toLocalString()
    }
}

依然报错。

😃 正解

filters: {
    convertNum (val) {
        if (val) return val.toLocalString()
    }
}

加一个 if 判断即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant