diff --git a/src/password-input/README.md b/src/password-input/README.md index 28ed5614a..e5cdd1e7b 100644 --- a/src/password-input/README.md +++ b/src/password-input/README.md @@ -33,11 +33,16 @@ app.use(NumberKeyboard); ``` ```js +import { ref } from 'vue'; + export default { - data() { + setup() { + const value = ref('123'); + const showKeyboard = ref(true); + return { - value: '123', - showKeyboard: true, + value, + showKeyboard, }; }, }; @@ -96,22 +101,27 @@ Use `info` to set info message, use `error-info` prop to set error message. ``` ```js +import { ref, watch } from 'vue'; + export default { - data() { - return { - value: '123', - errorInfo: '', - showKeyboard: true, - }; - }, - watch: { - value(value) { - if (value.length === 6 && value !== '123456') { - this.errorInfo = 'Password Mistake'; + setup() { + const value = ref('123'); + const errorInfo = ref(''); + const showKeyboard = ref(true); + + watch(value, (newVal) => { + if (newVal.length === 6 && newVal !== '123456') { + errorInfo.value = 'Password Mistake'; } else { - this.errorInfo = ''; + errorInfo.value = ''; } - }, + }); + + return { + value, + errorInfo, + showKeyboard, + }; }, }; ``` diff --git a/src/password-input/README.zh-CN.md b/src/password-input/README.zh-CN.md index d37c019d9..ccfb233de 100644 --- a/src/password-input/README.zh-CN.md +++ b/src/password-input/README.zh-CN.md @@ -37,11 +37,16 @@ app.use(NumberKeyboard); ``` ```js +import { ref } from 'vue'; + export default { - data() { + setup() { + const value = ref('123'); + const showKeyboard = ref(true); + return { - value: '123', - showKeyboard: true, + value, + showKeyboard, }; }, }; @@ -106,22 +111,27 @@ export default { ``` ```js +import { ref, watch } from 'vue'; + export default { - data() { - return { - value: '123', - errorInfo: '', - showKeyboard: true, - }; - }, - watch: { - value(value) { - if (value.length === 6 && value !== '123456') { - this.errorInfo = '密码错误'; + setup() { + const value = ref('123'); + const errorInfo = ref(''); + const showKeyboard = ref(true); + + watch(value, (newVal) => { + if (newVal.length === 6 && newVal !== '123456') { + errorInfo.value = '密码错误'; } else { - this.errorInfo = ''; + errorInfo.value = ''; } - }, + }); + + return { + value, + errorInfo, + showKeyboard, + }; }, }; ``` diff --git a/src/password-input/demo/index.vue b/src/password-input/demo/index.vue index 5baa08ff3..0224dcf90 100644 --- a/src/password-input/demo/index.vue +++ b/src/password-input/demo/index.vue @@ -52,54 +52,58 @@ /> -