zhangjihao
zhangjihao
  • 发布:2024-09-19 11:12
  • 更新:2024-09-19 11:23
  • 阅读:205

<uni-easyinput>组件如何通过编程获得焦点?

分类:uni-app

//html
<uni-easyinput placeholder="请输入" v-model="..." ref="inputRef" ></uni-easyinput>

//js
let inputRef = ref(null);

......
if(...){
inputRef.focus(); //没效果
inputRef.value.focus(); //没效果
inputRef.focus = true; //没效果
inputRef.value.focus = true; //没效果
}

2024-09-19 11:12 负责人:无 分享
已邀请:
靐齉齾麤龖龗

靐齉齾麤龖龗 - 解决不了问题,那就解决提出问题的人

<uni-easyinput placeholder="请输入" v-model="..." ref="inputRef" :focus="focus"></uni-easyinput>
const focus = ref(!1)

if(...){
focus.value = !0
}

DCloud_UNI_yuhe

DCloud_UNI_yuhe

给你提供一个示例,你看一下能不能满足你的要求:

<template>  
    <view>  
        <uni-easyinput :focus="focus" v-model="input" placeholder="" />  
        <button @click="click">click</button>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                input:'',  
                focus:false  
            }  
        },  
        onLoad() {  

        },  
        methods: {  
            click(){  
                this.focus = !this.focus  
            }  
        }  
    }  
</script>  

<style>  

</style>  

要回复问题请先登录注册