我正在尝试使用Vuejs 2获取keyup的输入值,但总是得到像数据一样的空结果。请参阅下面的代码。
HTML:
iew = db.getView("Team Documents\\By Date");
脚本:
<input type="email" @keyup="this.$data.email= $event.target.value" class="form-control" id="email" placeholder="Username (your work email)">
<button type="button" class="btn btn-primary btn-block inactive" @click="submit">Log in</button>
答案 0 :(得分:7)
您需要引用email
(不是this.$data.email
):
<input type="email" @keyup="email = $event.target.value" class="form-control" id="email" placeholder="Username (your work email)">
但是,为什么不使用v-model
将email
绑定到输入?
new Vue({
el: '#app',
data () {
return {
email: '',
}
},
methods: {
submit () {
alert(this.email)
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.min.js"></script>
<div id="app">
<input type="email" v-model="email" class="form-control" id="email" placeholder="Username (your work email)">
<button type="button" class="btn btn-primary btn-block inactive" @click="submit">Log in</button>
</div>
答案 1 :(得分:0)
@ keyup.enter.native =“ submitMETHOD”