【发布时间】:2016-01-22 08:06:36
【问题描述】:
我正在尝试在 Vue.js 中设置输入元素的焦点。我在网上找到了一些帮助,但没有一个对我有用。
这是我的代码:
<template>
<form method="post" action="" v-on:submit.prevent="search">
<input type="text" placeholder="Person name" required v-model="name" v-el="nameInput" />
<input type="text" placeholder="Company" required v-model="company" v-el="domainInput" />
<input type="submit" value="Search" class="btn show-m" />
</form>
</template>
<script>
export default {
data () {
return {
contacts: [],
name: null,
company: null
}
},
ready: {
// I tried the following :
this.$$.nameInput.focus();
this.$els.nameInput.focus();
// None of them worked !
}
methods: {
search: function (event) {
// ...
// I also would like to give the focus here, once the form has been submitted.
// And here also, this.$$ and this.$els doesn't work
},
}
}
</script>
我尝试了this.$$.nameInput.focus(); 和this.$els.nameInput.focus(); 来寻找我可以在网上找到的目标,但this.$$ 未定义,this.$els 为空。
如果有帮助,我正在使用 vue.js v1.0.15
感谢您的帮助。
【问题讨论】:
标签: javascript vue.js