Skip to content

Commit

Permalink
fix(plugin): clone the default items for slide,radio group, checkbox …
Browse files Browse the repository at this point in the history
…group

修复轮播图、多选组、单选组的默认值
  • Loading branch information
ly525 committed Nov 23, 2019
1 parent ea72021 commit 141036f
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 34 deletions.
32 changes: 20 additions & 12 deletions front-end/h5/src/components/plugins/lbp-form-checkbox-group.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import LbpFormRadio from './lbp-form-radio.js'

const defaultItems = [
{
value: '选项A'
},
{
value: '选项B'
},
{
value: '选项C'
}
]
function getDefaultItems () {
// defaultItems.slice(0)[0] === defaultItems.slice(0)[0] -> true
// Object.assign(defaultItems)[0] === Object.assign(defaultItems)[0] -> true
// clone = (val) => JSON.parse(JSON.stringify(val))
// clone(defaultItems)[0] === clone(defaultItems)[0] -> false
const defaultItems = [
{
value: '选项A'
},
{
value: '选项B'
},
{
value: '选项C'
}
]

return defaultItems
}

export default {
name: 'lbp-form-checkbox-group',
Expand All @@ -29,7 +37,7 @@ export default {
},
items: {
type: Array,
default: () => defaultItems,
default: () => getDefaultItems(),
editor: {
type: 'lbs-prop-text-enum-editor',
label: '选项列表',
Expand Down
44 changes: 31 additions & 13 deletions front-end/h5/src/components/plugins/lbp-form-radio-group.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
/*
* @Author: ly525
* @Date: 2019-11-23 12:35:43
* @LastEditors: ly525
* @LastEditTime: 2019-11-23 19:50:57
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-form-radio-group.js
* @Github: https://github.com/ly525/luban-h5
* @Description: 表单单选组组件 #!en: radio group component
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
*/

import LbpFormRadio from './lbp-form-radio.js'
// import { genUUID } from '../../utils/element.js'

const defaultItems = [
{
value: '选项A'
},
{
value: '选项B'
},
{
value: '选项C'
}
]
function getDefaultItems () {
// defaultItems.slice(0)[0] === defaultItems.slice(0)[0] -> true
// Object.assign(defaultItems)[0] === Object.assign(defaultItems)[0] -> true
// clone = (val) => JSON.parse(JSON.stringify(val))
// clone(defaultItems)[0] === clone(defaultItems)[0] -> false
const defaultItems = [
{
value: '选项A'
},
{
value: '选项B'
},
{
value: '选项C'
}
]

return defaultItems
}

export default {
name: 'lbp-form-radio-group',
Expand All @@ -27,7 +45,7 @@ export default {
},
items: {
type: Array,
default: () => defaultItems,
default: () => getDefaultItems(),
editor: {
type: 'lbs-prop-text-enum-editor',
label: '选项列表',
Expand Down
33 changes: 24 additions & 9 deletions front-end/h5/src/components/plugins/lbp-slide.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
/*
* @Author: ly525
* @Date: 2019-11-23 12:35:21
* @LastEditors: ly525
* @LastEditTime: 2019-11-23 19:53:14
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-slide.js
* @Github: https://github.com/ly525/luban-h5
* @Description: #!zh: 轮播图组件 #!en slide component
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
*/

import { Swipe, SwipeItem } from 'vant'
import 'vant/lib/swipe/style'
import 'vant/lib/swipe-item/style'

const defaultItems = [
{
image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
},
{
image: 'https://img.yzcdn.cn/vant/apple-2.jpg'
}
]
function getDefaultItems () {
const defaultItems = [
{
image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
},
{
image: 'https://img.yzcdn.cn/vant/apple-2.jpg'
}
]

return defaultItems
}

export default {
name: 'lbp-slide',
Expand All @@ -36,7 +51,7 @@ export default {
},
items: {
type: Array,
default: () => defaultItems.slice(0),
default: () => getDefaultItems(),
editor: {
custom: true
}
Expand Down

0 comments on commit 141036f

Please sign in to comment.