gpt4 book ai didi

vue.js - 模态自动对焦上的 bootstrap vue 输入

转载 作者:行者123 更新时间:2023-12-03 06:37:38 27 4
gpt4 key购买 nike

我在模态上有一个 bootstrap-vue 输入

<b-form-input  id="inputText1" ref="inputText1" v-model="inputText" autofocus></b-form-input>

模态是 bootstrap-vue 模态,显示/隐藏由 v-if 指令控制。

当模态打开时,输入具有焦点。如果我关闭模态输入不再有焦点。

每次安装模态时,我都尝试设置自动对焦属性,但它仍然没有对焦。我也试过使用 $nextTick 。

最佳答案

我建议你使用 v-model 和 vue bootstrap modal

模板

    <template>
<div>
<b-button @click="showModal= !showModal">Open your bmodal</b-button>
<b-modal v-model="showModal">Yor modal is active!</b-modal>
<b-form-input id="inputText1" ref="inputText1" v-model="inputText" autofocus></b-form-input>

</div>
</template>

vue 代码
    new Vue({
el: '#app',
data() {
return {
showModal: false
}
},
watch:{
showModal:function(value){
// set the focus when the modal opened/closed
this.$refs.inputText1.focus();
}
},
mounted(){
// set the focus when the component opened
this.$refs.inputText1.focus();
},
methods: {

}
});

关于vue.js - 模态自动对焦上的 bootstrap vue 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57037294/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com