File tree Expand file tree Collapse file tree 4 files changed +29
-31
lines changed Expand file tree Collapse file tree 4 files changed +29
-31
lines changed Original file line number Diff line number Diff line change 6
6
"current" : 0 , //当前激活的模式(list 的索引项)
7
7
"list" : [{
8
8
"name" : " test" , //模式名称
9
- "path" : " pages/componentsC/test /index" , //启动页面,必选
9
+ "path" : " pages/componentsB/search /index" , //启动页面,必选
10
10
"query" : " id=1&name=2" //启动参数,在页面的onLoad函数里面得到
11
11
}]
12
12
},
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<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"
6
7
v-for =" (item, index) in list" :key =" index"
7
8
: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 >
13
12
</view >
14
13
</template >
15
14
@@ -19,30 +18,37 @@ export default {
19
18
return {
20
19
list: [
21
20
{
22
- name: 1 ,
21
+ name: ' apple' ,
22
+ checked: false ,
23
23
disabled: false
24
24
},
25
25
{
26
- name: 2 ,
26
+ name: ' banner' ,
27
+ checked: false ,
27
28
disabled: false
28
29
},
29
30
{
30
- name: 3 ,
31
+ name: ' orange' ,
32
+ checked: false ,
31
33
disabled: false
32
34
}
33
- ],
34
- // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
35
- value: 1 ,
35
+ ]
36
36
};
37
37
},
38
38
methods: {
39
- // 选中某个单选框时,由radio时触发
40
- radioChange (e ) {
41
- // console.log(e);
39
+ // 选中某个复选框时,由checkbox时触发
40
+ checkboxChange (e ) {
41
+ console .log (e);
42
42
},
43
- // 选中任一radio时,由radio -group触发
44
- radioGroupChange (e ) {
43
+ // 选中任一checkbox时,由checkbox -group触发
44
+ checkboxGroupChange (e ) {
45
45
// console.log(e);
46
+ },
47
+ // 全选
48
+ checkedAll () {
49
+ this .list .map (val => {
50
+ val .checked = true ;
51
+ })
46
52
}
47
53
}
48
54
};
Original file line number Diff line number Diff line change 183
183
},
184
184
emitEvent () {
185
185
// 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 );
191
187
},
192
188
// 改变组件选中状态
193
189
// 这里的改变的依据是,更改本组件的parentData.value值为本组件的name值,同时通过父组件遍历所有u-radio实例
Original file line number Diff line number Diff line change 22
22
@input =" inputChange"
23
23
:disabled =" disabled"
24
24
@focus =" getFocus"
25
- :maxlength =" getMaxlength"
26
25
:focus =" focus"
26
+ :maxlength =" maxlength"
27
27
placeholder-class =" u-placeholder-class"
28
28
:placeholder =" placeholder"
29
29
:placeholder-style =" `color: ${placeholderColor}`"
@@ -164,7 +164,7 @@ export default {
164
164
// 输入框最大能输入的长度,-1为不限制长度(来自uniapp文档)
165
165
maxlength: {
166
166
type: [Number , String ],
167
- default: - 1
167
+ default: ' -1 '
168
168
},
169
169
// 搜索图标的颜色,默认同输入框字体颜色
170
170
searchIconColor: {
@@ -227,10 +227,6 @@ export default {
227
227
if (this .borderColor ) return ` 1px solid ${ this .borderColor } ` ;
228
228
else return ' none' ;
229
229
},
230
- // 将maxlength转为数值
231
- getMaxlength () {
232
- return Number (this .maxlength );
233
- }
234
230
},
235
231
methods: {
236
232
// 目前HX2.6.9 v-model双向绑定无效,故监听input事件获取输入框内容的变化
You can’t perform that action at this time.
0 commit comments