前言
在 uni-app 扩展组件(uni-ui)的使用过程中,可能会遇到与文档表现不一致的问题;我在使用过程中就遇到这种问题,例如:uni-search-bar 搜索栏组件
具体表现
1. @focus 、@blur 事件不可用
2. v-model 绑定后,其值变成 { value: “xxx” } 形式,且无法为其手动赋值(this.searchValue = "xxx"
)
找原因
我找到 components/uni-search-bar 文件夹下的组件代码,发现代码里没有抛出 focus 和 blur 事件,且抛出的input事件的返回值为 { value: this.searchVal }
代码如下:
watch: {
searchVal() {
this.$emit("input", {
value: this.searchVal
})
}
},