在使用 iview 的 render 渲染函数时,我们动态生成的 Input 输入框,自动获取焦点时,只能第一次获取到焦点,我们可以使用原生的 js 获取焦点,使用ref 无效,原因未知。
render:(h,params)=>{
if( params.row.$editablejiage ) {
return h('Input',{
props: {
type: "number",
value: params.row.purchaseprice,
autofocus: true,
},
attrs:{
// ref: 'no',
class:'replyBox',
},
on:{
"on-blur":event=>{
params.row.purchaseprice = event.target.value
this.$set(params.row, '$editablejiage', false);
}
}
})
} else {
return h('div',{
on:{
click:()=>{
setTimeout( ()=> {
this.$nextTick(()=>{
document.getElementsByClassName('replyBox')[0].childNodes[6].focus()
// this.$refs.replyBox[0].focus()
})
},300);
this.$set(params.row, '$editablejiage', true);
}
}
},params.row.purchaseprice)
}
}