Commit 141036f7060e49b880fff18d18cf3ff5537a8576
1 parent
ea72021f
fix(plugin): clone the default items for slide,radio group, checkbox group
修复轮播图、多选组、单选组的默认值
Showing
3 changed files
with
75 additions
and
34 deletions
front-end/h5/src/components/plugins/lbp-form-checkbox-group.js
| 1 | import LbpFormRadio from './lbp-form-radio.js' | 1 | import LbpFormRadio from './lbp-form-radio.js' |
| 2 | 2 | ||
| 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 | +} | ||
| 14 | 22 | ||
| 15 | export default { | 23 | export default { |
| 16 | name: 'lbp-form-checkbox-group', | 24 | name: 'lbp-form-checkbox-group', |
| @@ -29,7 +37,7 @@ export default { | @@ -29,7 +37,7 @@ export default { | ||
| 29 | }, | 37 | }, |
| 30 | items: { | 38 | items: { |
| 31 | type: Array, | 39 | type: Array, |
| 32 | - default: () => defaultItems, | 40 | + default: () => getDefaultItems(), |
| 33 | editor: { | 41 | editor: { |
| 34 | type: 'lbs-prop-text-enum-editor', | 42 | type: 'lbs-prop-text-enum-editor', |
| 35 | label: '选项列表', | 43 | label: '选项列表', |
front-end/h5/src/components/plugins/lbp-form-radio-group.js
| 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 | + | ||
| 1 | import LbpFormRadio from './lbp-form-radio.js' | 12 | import LbpFormRadio from './lbp-form-radio.js' |
| 2 | -// import { genUUID } from '../../utils/element.js' | ||
| 3 | 13 | ||
| 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 | +} | ||
| 15 | 33 | ||
| 16 | export default { | 34 | export default { |
| 17 | name: 'lbp-form-radio-group', | 35 | name: 'lbp-form-radio-group', |
| @@ -27,7 +45,7 @@ export default { | @@ -27,7 +45,7 @@ export default { | ||
| 27 | }, | 45 | }, |
| 28 | items: { | 46 | items: { |
| 29 | type: Array, | 47 | type: Array, |
| 30 | - default: () => defaultItems, | 48 | + default: () => getDefaultItems(), |
| 31 | editor: { | 49 | editor: { |
| 32 | type: 'lbs-prop-text-enum-editor', | 50 | type: 'lbs-prop-text-enum-editor', |
| 33 | label: '选项列表', | 51 | label: '选项列表', |
front-end/h5/src/components/plugins/lbp-slide.js
| 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 | + | ||
| 1 | import { Swipe, SwipeItem } from 'vant' | 12 | import { Swipe, SwipeItem } from 'vant' |
| 2 | import 'vant/lib/swipe/style' | 13 | import 'vant/lib/swipe/style' |
| 3 | import 'vant/lib/swipe-item/style' | 14 | import 'vant/lib/swipe-item/style' |
| 4 | 15 | ||
| 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 | +} | ||
| 13 | 28 | ||
| 14 | export default { | 29 | export default { |
| 15 | name: 'lbp-slide', | 30 | name: 'lbp-slide', |
| @@ -36,7 +51,7 @@ export default { | @@ -36,7 +51,7 @@ export default { | ||
| 36 | }, | 51 | }, |
| 37 | items: { | 52 | items: { |
| 38 | type: Array, | 53 | type: Array, |
| 39 | - default: () => defaultItems.slice(0), | 54 | + default: () => getDefaultItems(), |
| 40 | editor: { | 55 | editor: { |
| 41 | custom: true | 56 | custom: true |
| 42 | } | 57 | } |