1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <template> <div id="app"> <form> <input type="text" @click="input" v-model="inputValue" placeholder="请输入验证码"/> <button type="submit">提交</button> </form> <custom-keyboard :keyboardShow.sync="show" :value.sync="inputValue"></custom-keyboard> </div> </template>
<script>
export default { data() { return { inputValue: '', show: false, customKeyboard: [ [{key: '1', label: '1'}, {key: '2', label: '2'}, {key: '3', label: '3'}], [{key: '4', label: '4'}, {key: '5', label: '5'}, {key: '6', label: '6'}], [{key: '7', label: '7'}, {key: '8', label: '8'}, {key: '9', label: '9'}], [{key: 'CLEAR', label: '清空'}, {key: '0', label: '0'}, {key: 'DELETE', label: '删除'}], ]
} }, methods: { input() { this.show = true document.activeElement.setAttribute('readonly', 'readonly') setTimeout(() => { document.activeElement.removeAttribute('readonly') }); }, confirm() { alert(this.inputValue) } } } </script>
|