mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] PasswordInput: jsx (#2611)
This commit is contained in:
parent
b51b77687e
commit
30159884b4
51
packages/password-input/index.js
Normal file
51
packages/password-input/index.js
Normal file
@ -0,0 +1,51 @@
|
||||
import { use } from '../utils';
|
||||
|
||||
const [sfc, bem] = use('password-input');
|
||||
|
||||
export default sfc({
|
||||
props: {
|
||||
info: String,
|
||||
errorInfo: String,
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
length: {
|
||||
type: Number,
|
||||
default: 6
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
points() {
|
||||
const arr = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
arr[i] = this.value[i] ? 'visible' : 'hidden';
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
},
|
||||
|
||||
render(h) {
|
||||
const info = this.errorInfo || this.info;
|
||||
|
||||
return (
|
||||
<div class={bem()}>
|
||||
<ul
|
||||
class={[bem('security'), 'van-hairline--surround']}
|
||||
onTouchstart={event => {
|
||||
event.stopPropagation();
|
||||
this.$emit('focus');
|
||||
}}
|
||||
>
|
||||
{this.points.map(visibility => (
|
||||
<li class="van-hairline">
|
||||
<i style={{ visibility }} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{info && <div class={bem(this.errorInfo ? 'error-info' : 'info')}>{info}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
@ -1,52 +0,0 @@
|
||||
<template>
|
||||
<div :class="b()">
|
||||
<ul
|
||||
:class="b('security')"
|
||||
class="van-hairline--surround"
|
||||
@touchstart.stop="$emit('focus')"
|
||||
>
|
||||
<li
|
||||
v-for="visibility in points"
|
||||
class="van-hairline"
|
||||
>
|
||||
<i :style="{ visibility } " />
|
||||
</li>
|
||||
</ul>
|
||||
<div
|
||||
v-if="errorInfo || info"
|
||||
v-text="errorInfo || info"
|
||||
:class="b(errorInfo ? 'error-info' : 'info')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import create from '../utils/create';
|
||||
|
||||
export default create({
|
||||
name: 'password-input',
|
||||
|
||||
props: {
|
||||
info: String,
|
||||
errorInfo: String,
|
||||
value: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
length: {
|
||||
type: Number,
|
||||
default: 6
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
points() {
|
||||
const arr = [];
|
||||
for (let i = 0; i < this.length; i++) {
|
||||
arr[i] = this.value[i] ? 'visible' : 'hidden';
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
@ -4,7 +4,7 @@ exports[`renders demo correctly 1`] = `
|
||||
<div>
|
||||
<div>
|
||||
<div class="van-password-input">
|
||||
<ul class="van-hairline--surround van-password-input__security">
|
||||
<ul class="van-password-input__security van-hairline--surround">
|
||||
<li class="van-hairline"><i style="visibility:visible;"></i></li>
|
||||
<li class="van-hairline"><i style="visibility:visible;"></i></li>
|
||||
<li class="van-hairline"><i style="visibility:visible;"></i></li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user