Vue.jsで入力要素のフォーカスを設定しようとしています。私はオンラインで助けを見つけましたが、説明のどれも私のために働いていませんでした。vue.jsの入力要素のフォーカスを設定する
は、ここに私のコードです:私はフォーカスをターゲットとしたオンライン見つけることができる何のためthis.$$.nameInput.focus();
とthis.$els.nameInput.focus();
を試してみました
<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.$$
は未定義であり、this.$els
は空です。それは助けることができるならば、私はvue.js v1.0.15に
を使用してい
はあなたの助けをいただき、ありがとうございます。
、なぜこのよう:
次に、あなたが入力し、他の要素に
v-focus
属性を使用することができますか? (もし何か考えがあるなら)。 'v-el =" XXX "'はもっと論理的なものですか? –しかしこれはうまくいくので、私の受け入れられた答えがあります:)ありがとう –
[This](https://github.com/vuejs/vue/issues/1292)は、現在の機能に関する基本的な思考プロセスです。 – Andrius