1***@qq.com
1***@qq.com
  • 发布:2020-08-22 12:08
  • 更新:2020-08-22 13:43
  • 阅读:6276

input聚焦 this.$refs.input[index].focus() is not a function???

分类:uni-app
<template> <view class="forgot"> <view class="text-area"> <view class="title"> <text class="X_title">Verify your Mobile</text> </view> <text class="DEC">Enter your OTP code here</text> </view> <view class="form"> <view class="input"> <view class="point_container"> <view class="point" v-for="(item,index) of obj" :key="index"> <view class="deep_point"> <input name="input" class="deep_point" type="number" maxlength="1" ref='input' @input="changeInput" @focus="onFocus" data-id="index" v-model="obj[index]"
>
</view>
</view>
</view>
</view>
</view>
<button class="userLocation">
<text class="b_content">
Verify Now
</text>
</button>
</view>
</template>

<script>
export default{
data(){
return{
num:2,
that:this,
obj:['','','','']
}
},
computed:{
ctSize() {
return this.obj.length;
},
},
methods:{
changeInput(e){
console.log(this.ctSize)
},
focus(){
console.log("获得焦点")
},
onFocus(){
let index =this.obj.findIndex(item=>{return item ==''})
index=(index+this.ctSize) % this.ctSize;
console.log(index)
console.log(this.$refs.input[index])
this.$refs.input[index].focus();

        }  
    }  
}  

</script>

2020-08-22 12:08 负责人:无 分享
已邀请:

最佳回复

深海智行

深海智行 - 专注前端培训

ref 不对吧,怎么都是 input

  • 1***@qq.com (作者)

    是这样的,我ref获取到了,但是focus调不到

    2020-08-22 13:50

  • 深海智行

    回复 1***@qq.com: 哦,你用错了,不是这么用的,你看文档,设置focus属性

    2020-08-22 17:31

  • 1***@qq.com (作者)

    回复 深海智行:直接设置属性就会 报这个错Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "focus"所以没用

    2020-08-22 19:12

  • 深海智行

    回复 1***@qq.com: 哦,你还是用错了,这样: : focus="focus"

    2020-08-24 16:56

该问题目前已经被锁定, 无法添加新回复