Vue.component('com1', {
template: '#com1',
data() {
return {
code: ''
}
},
methods: {
onkeypress(e) {
if (e.keyCode === 13) {
const val = e.target.value
if (val === this.code) {
this.$emit('done', val)
}
else {
this.$emit('error')
}
this.code = ''
e.target.value = ''
}
else {
const keychar = String.fromCharCode(e.keyCode)
this.code += keychar
}
},
onfocus(e) {
this.code = ''
e.target.value = ''
}
}
})
new Vue({
el: '#app',
methods: {