我在尝试通过按下 android/ios 键盘中的下一个按钮将焦点从一个输入更改为另一个输入时遇到困难,因为没有使用 setFocus 方法的示例。
也许这里有人已经实现了这一点?谁能给我看一些例子?
到目前为止我已经尝试过:
Form.vue
<template>
<form @submit.prevent="onSubmit">
<form-input
enterkeyhint="next"
v-model="email"
@keyup.enter="changeFocus('password')"
/>
<form-input
ref="password"
v-model="password"
/>
</form>
</template>
<script lang="ts">
// ... some import statements
export default defineComponent({
setup() {
const email = ref("");
const password = ref("");
return {
email,
password,
};
},
methods: {
changeFocus(nextFocus: string): void {
this.$refs[nextFocus].setFocus();
},
},
});
</script>
errors
TS2571: Object is of type 'unknown'.
[vue-cli-service] 80 | methods: {
[vue-cli-service] 81 | changeFocus(nextFocus: string): void {
[vue-cli-service] > 82 | this.$refs[nextFocus].setFocus();
[vue-cli-service] | ^^^^^^^^^^^^^^^^^^^^^
[vue-cli-service] 83 | },
[vue-cli-service] 84 | },
[vue-cli-service] 85 | });