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

[Bug Report] inputNumber data cannot be displayed synchronously #12244

Closed
yuminjustin opened this issue Aug 6, 2018 · 5 comments
Closed

[Bug Report] inputNumber data cannot be displayed synchronously #12244

yuminjustin opened this issue Aug 6, 2018 · 5 comments

Comments

@yuminjustin
Copy link

Element UI version

2.4.5

OS/Browsers version

win10/chromium 63

Vue version

2.5.17

Reproduction Link

http://jsfiddle.net/L3w6mrt2/2//

Steps to reproduce

链接中的示例:手动输入1.6,进入绑定的change事件中,把组件state改成非浮点数。由于初始值就是1,输入的1.6,使用Math.floor的方法将值改成了1,组件的test实际为1,但界面依然是1.6。除非另外输入2.6,界面就会显示成2。

What is Expected?

其实我就是新作一个禁止输入浮点数的功能

What is actually happening?

当change事件中经过处理后的值跟原来的值相同时,无法变更界面显示。

@element-bot element-bot changed the title [Bug Report] inputNumber数据无法同步显示 [Bug Report] inputNumber data cannot be displayed synchronously Aug 6, 2018
@element-bot
Copy link
Member

Translation of this issue:

Element UI version
2.4.5

OS/Browsers version
Win10/chromium 63

Vue version
2.5.17

Reproduction Link
http://jsfiddle.net/L3w6mrt2/2//

Steps to reproduce
Example in the link: manually enter 1.6, enter the change event of the binding, and change the component state to a non floating point number. Since the initial value is 1 and the input value is 1.6, the value is changed to 1 using the Math. floor method. The test of the component is actually 1, but the interface is still 1.6. Unless another 2.6 is entered, the interface will display 2.

What is Expected?
In fact, I am the new function of prohibiting the importation of floating point numbers.

What is actually happening?
The interface display can not be changed when the processed value in the change event is the same as the original value.

@yuminjustin
Copy link
Author

刚才尝试一下把change事件做了一下改变:

        handleNum(value) {
            this.test = value * 100;
            setTimeout(() => {
                if (!/^[1-9]\d*$/.test(value)) {
                    this.test = Math.floor(value);
                }
            }, 10)

        }

可以达到目的,但是感觉这样太low了

@ziyoung
Copy link
Contributor

ziyoung commented Aug 6, 2018

只输入整数吗?试试设置 precision 属性。https://jsfiddle.net/zhiyang/yt6cm0e1/

@ziyoung ziyoung closed this as completed Aug 6, 2018
@yuminjustin
Copy link
Author

yuminjustin commented Aug 6, 2018

@ziyoung 你的例子的确可以用,但是很奇怪 precision = 0
官方文档里面:http://element-cn.eleme.io/#/zh-CN/component/input-number
image
precision的值必须是一个正整数
。。。。。。。
所以我都没去用这个

@ziyoung
Copy link
Contributor

ziyoung commented Aug 6, 2018

@yuminjustin 文档描述的有问题😅,precision 应该是大于或者等于 0 的整数才对。

precision: {
type: Number,
validator(val) {
return val >= 0 && val === parseInt(val, 10);

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

3 participants