Skip to content

Commit 01156d4

Browse files
committed
1. 优化search组件的maxlength下的问题
2. 修复radio组件的change时间不触发的问题
1 parent 15f867f commit 01156d4

File tree

4 files changed

+29
-31
lines changed

4 files changed

+29
-31
lines changed

pages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"current": 0, //当前激活的模式(list 的索引项)
77
"list": [{
88
"name": "test", //模式名称
9-
"path": "pages/componentsC/test/index", //启动页面,必选
9+
"path": "pages/componentsB/search/index", //启动页面,必选
1010
"query": "id=1&name=2" //启动参数,在页面的onLoad函数里面得到
1111
}]
1212
},

pages/componentsC/test/index.vue

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<template>
22
<view class="">
3-
<u-radio-group v-model="value" @change="radioGroupChange">
4-
<u-radio
5-
@change="radioChange"
3+
<u-checkbox-group @change="checkboxGroupChange">
4+
<u-checkbox
5+
@change="checkboxChange"
6+
v-model="item.checked"
67
v-for="(item, index) in list" :key="index"
78
:name="item.name"
8-
:disabled="item.disabled"
9-
>
10-
{{item.name}}
11-
</u-radio>
12-
</u-radio-group>
9+
>{{item.name}}</u-checkbox>
10+
</u-checkbox-group>
11+
<u-button @click="checkedAll">全选</u-button>
1312
</view>
1413
</template>
1514

@@ -19,30 +18,37 @@ export default {
1918
return {
2019
list: [
2120
{
22-
name: 1,
21+
name: 'apple',
22+
checked: false,
2323
disabled: false
2424
},
2525
{
26-
name: 2,
26+
name: 'banner',
27+
checked: false,
2728
disabled: false
2829
},
2930
{
30-
name: 3,
31+
name: 'orange',
32+
checked: false,
3133
disabled: false
3234
}
33-
],
34-
// u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
35-
value: 1,
35+
]
3636
};
3737
},
3838
methods: {
39-
// 选中某个单选框时,由radio时触发
40-
radioChange(e) {
41-
// console.log(e);
39+
// 选中某个复选框时,由checkbox时触发
40+
checkboxChange(e) {
41+
console.log(e);
4242
},
43-
// 选中任一radio时,由radio-group触发
44-
radioGroupChange(e) {
43+
// 选中任一checkbox时,由checkbox-group触发
44+
checkboxGroupChange(e) {
4545
// console.log(e);
46+
},
47+
// 全选
48+
checkedAll() {
49+
this.list.map(val => {
50+
val.checked = true;
51+
})
4652
}
4753
}
4854
};

uview-ui/components/u-radio/u-radio.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,7 @@
183183
},
184184
emitEvent() {
185185
// u-radio的name不等于父组件的v-model的值时(意味着未选中),才发出事件,避免多次点击触发事件
186-
// 等待下一个周期再执行,因为this.$emit('input')作用于父组件,再反馈到子组件内部,需要时间
187-
// 头条需要延时的时间比较长,这里给比较大的值
188-
setTimeout(() => {
189-
if(this.parentData.value != this.name) this.$emit('change', this.name);
190-
}, 80);
186+
if(this.parentData.value != this.name) this.$emit('change', this.name);
191187
},
192188
// 改变组件选中状态
193189
// 这里的改变的依据是,更改本组件的parentData.value值为本组件的name值,同时通过父组件遍历所有u-radio实例

uview-ui/components/u-search/u-search.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
@input="inputChange"
2323
:disabled="disabled"
2424
@focus="getFocus"
25-
:maxlength="getMaxlength"
2625
:focus="focus"
26+
:maxlength="maxlength"
2727
placeholder-class="u-placeholder-class"
2828
:placeholder="placeholder"
2929
:placeholder-style="`color: ${placeholderColor}`"
@@ -164,7 +164,7 @@ export default {
164164
// 输入框最大能输入的长度,-1为不限制长度(来自uniapp文档)
165165
maxlength: {
166166
type: [Number, String],
167-
default: -1
167+
default: '-1'
168168
},
169169
// 搜索图标的颜色,默认同输入框字体颜色
170170
searchIconColor: {
@@ -227,10 +227,6 @@ export default {
227227
if (this.borderColor) return `1px solid ${this.borderColor}`;
228228
else return 'none';
229229
},
230-
// 将maxlength转为数值
231-
getMaxlength() {
232-
return Number(this.maxlength);
233-
}
234230
},
235231
methods: {
236232
// 目前HX2.6.9 v-model双向绑定无效,故监听input事件获取输入框内容的变化

0 commit comments

Comments
 (0)