我试图在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.JSV1.0.15
谢谢你的帮助.