此处使用的是vant框架
解决聚焦问题
这里遇到的问题是,在点击搜索框后,设置了弹起的弹出层中van-search的foucs值为true
但是没有起到聚焦效果
原因在于弹出框带有一个动画效果,需要在动画效果之后再使focus的值为true才能生效
关键代码如下
focus="{ {isfocus}}"
model:value="{ { searchValue }}"
placeholder="请输入您要搜索的值"
/>
js中
lifetimes: {
attached: function() {
setTimeout(()=>{
this.setData({
isfocus:true
})
},800)
}
},
顺便记录下封装组件遇到的一些问题
需要先将json中设置"component":true
js的Component中设置options 这是为了可以使用父组件中的样式
options:{
styleIsolation:"shared"
},
当封装弹出框组件时(vue同样适用)
子组件设置一个properties接收父组件传来的值fromparents
再设置一个data:isDialogShow,监测fromparents值的变化并赋值给这个data
不直接赋予是因为propert