Skip to content

Commit 141036f

Browse files
committed
fix(plugin): clone the default items for slide,radio group, checkbox group
修复轮播图、多选组、单选组的默认值
1 parent ea72021 commit 141036f

File tree

3 files changed

+75
-34
lines changed

3 files changed

+75
-34
lines changed

front-end/h5/src/components/plugins/lbp-form-checkbox-group.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
import LbpFormRadio from './lbp-form-radio.js'
22

3-
const defaultItems = [
4-
{
5-
value: '选项A'
6-
},
7-
{
8-
value: '选项B'
9-
},
10-
{
11-
value: '选项C'
12-
}
13-
]
3+
function getDefaultItems () {
4+
// defaultItems.slice(0)[0] === defaultItems.slice(0)[0] -> true
5+
// Object.assign(defaultItems)[0] === Object.assign(defaultItems)[0] -> true
6+
// clone = (val) => JSON.parse(JSON.stringify(val))
7+
// clone(defaultItems)[0] === clone(defaultItems)[0] -> false
8+
const defaultItems = [
9+
{
10+
value: '选项A'
11+
},
12+
{
13+
value: '选项B'
14+
},
15+
{
16+
value: '选项C'
17+
}
18+
]
19+
20+
return defaultItems
21+
}
1422

1523
export default {
1624
name: 'lbp-form-checkbox-group',
@@ -29,7 +37,7 @@ export default {
2937
},
3038
items: {
3139
type: Array,
32-
default: () => defaultItems,
40+
default: () => getDefaultItems(),
3341
editor: {
3442
type: 'lbs-prop-text-enum-editor',
3543
label: '选项列表',

front-end/h5/src/components/plugins/lbp-form-radio-group.js

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1+
/*
2+
* @Author: ly525
3+
* @Date: 2019-11-23 12:35:43
4+
* @LastEditors: ly525
5+
* @LastEditTime: 2019-11-23 19:50:57
6+
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-form-radio-group.js
7+
* @Github: https://github.com/ly525/luban-h5
8+
* @Description: 表单单选组组件 #!en: radio group component
9+
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
10+
*/
11+
112
import LbpFormRadio from './lbp-form-radio.js'
2-
// import { genUUID } from '../../utils/element.js'
313

4-
const defaultItems = [
5-
{
6-
value: '选项A'
7-
},
8-
{
9-
value: '选项B'
10-
},
11-
{
12-
value: '选项C'
13-
}
14-
]
14+
function getDefaultItems () {
15+
// defaultItems.slice(0)[0] === defaultItems.slice(0)[0] -> true
16+
// Object.assign(defaultItems)[0] === Object.assign(defaultItems)[0] -> true
17+
// clone = (val) => JSON.parse(JSON.stringify(val))
18+
// clone(defaultItems)[0] === clone(defaultItems)[0] -> false
19+
const defaultItems = [
20+
{
21+
value: '选项A'
22+
},
23+
{
24+
value: '选项B'
25+
},
26+
{
27+
value: '选项C'
28+
}
29+
]
30+
31+
return defaultItems
32+
}
1533

1634
export default {
1735
name: 'lbp-form-radio-group',
@@ -27,7 +45,7 @@ export default {
2745
},
2846
items: {
2947
type: Array,
30-
default: () => defaultItems,
48+
default: () => getDefaultItems(),
3149
editor: {
3250
type: 'lbs-prop-text-enum-editor',
3351
label: '选项列表',

front-end/h5/src/components/plugins/lbp-slide.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
/*
2+
* @Author: ly525
3+
* @Date: 2019-11-23 12:35:21
4+
* @LastEditors: ly525
5+
* @LastEditTime: 2019-11-23 19:53:14
6+
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-slide.js
7+
* @Github: https://github.com/ly525/luban-h5
8+
* @Description: #!zh: 轮播图组件 #!en slide component
9+
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
10+
*/
11+
112
import { Swipe, SwipeItem } from 'vant'
213
import 'vant/lib/swipe/style'
314
import 'vant/lib/swipe-item/style'
415

5-
const defaultItems = [
6-
{
7-
image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
8-
},
9-
{
10-
image: 'https://img.yzcdn.cn/vant/apple-2.jpg'
11-
}
12-
]
16+
function getDefaultItems () {
17+
const defaultItems = [
18+
{
19+
image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
20+
},
21+
{
22+
image: 'https://img.yzcdn.cn/vant/apple-2.jpg'
23+
}
24+
]
25+
26+
return defaultItems
27+
}
1328

1429
export default {
1530
name: 'lbp-slide',
@@ -36,7 +51,7 @@ export default {
3651
},
3752
items: {
3853
type: Array,
39-
default: () => defaultItems.slice(0),
54+
default: () => getDefaultItems(),
4055
editor: {
4156
custom: true
4257
}

0 commit comments

Comments
 (0)