提交 9ccd8f64 编写于 作者: Q qiang

fix: 修复H5端picker组件value错误时内部报错的问题

上级 1a462956
...@@ -156,7 +156,7 @@ export default { ...@@ -156,7 +156,7 @@ export default {
}, },
data () { data () {
return { return {
valueSync: this.value || 0, valueSync: null,
visible: false, visible: false,
valueChangeSource: '', valueChangeSource: '',
timeArray: [], timeArray: [],
...@@ -207,20 +207,17 @@ export default { ...@@ -207,20 +207,17 @@ export default {
} }
}, },
watch: { watch: {
value (val) { value () {
if (Array.isArray(val)) { this._setValueSync()
if (!Array.isArray(this.valueSync)) { },
this.valueSync = [] mode () {
} this._setValueSync()
this.valueSync.length = val.length },
val.forEach((val, index) => { range () {
if (val !== this.valueSync[index]) { this._setValueSync()
this.$set(this.valueSync, index, val) },
} valueSync () {
}) this._setValueArray()
} else if (typeof val !== 'object') {
this.valueSync = val
}
}, },
valueArray (val) { valueArray (val) {
if (this.mode === mode.TIME || this.mode === mode.DATE) { if (this.mode === mode.TIME || this.mode === mode.DATE) {
...@@ -269,8 +266,7 @@ export default { ...@@ -269,8 +266,7 @@ export default {
}) })
this._createTime() this._createTime()
this._createDate() this._createDate()
this.$watch('valueSync', this._setValue) this._setValueSync()
this.$watch('mode', this._setValue)
}, },
beforeDestroy () { beforeDestroy () {
this.$refs.picker.remove() this.$refs.picker.remove()
...@@ -285,7 +281,6 @@ export default { ...@@ -285,7 +281,6 @@ export default {
return return
} }
this.valueChangeSource = '' this.valueChangeSource = ''
this._setValue()
var $picker = this.$refs.picker var $picker = this.$refs.picker
$picker.remove(); $picker.remove();
(document.querySelector('uni-app') || document.body).appendChild($picker) (document.querySelector('uni-app') || document.body).appendChild($picker)
...@@ -346,13 +341,34 @@ export default { ...@@ -346,13 +341,34 @@ export default {
val1[i] = val2[i] val1[i] = val2[i]
} }
}, },
_setValue () { _setValueSync () {
let val = this.value
switch (this.mode) {
case mode.MULTISELECTOR:
if (!Array.isArray(val)) {
val = []
}
if (!Array.isArray(this.valueSync)) {
this.valueSync = []
}
const length = this.valueSync.length = Math.max(val.length, this.range.length)
for (let index = 0; index < length; index++) {
this.valueSync.splice(index, 1, Number(val[index]) || Number(this.valueSync[index]) || 0)
}
break
case mode.TIME:
case mode.DATE:
this.valueSync = String(val)
break
default:
this.valueSync = Number(val) || 0
break
}
},
_setValueArray () {
var val = this.valueSync var val = this.valueSync
var valueArray var valueArray
switch (this.mode) { switch (this.mode) {
case mode.SELECTOR:
valueArray = [val]
break
case mode.MULTISELECTOR: case mode.MULTISELECTOR:
valueArray = [...val] valueArray = [...val]
break break
...@@ -366,6 +382,9 @@ export default { ...@@ -366,6 +382,9 @@ export default {
mode: mode.DATE mode: mode.DATE
})) }))
break break
default:
valueArray = [val]
break
} }
this.oldValueArray = [...valueArray] this.oldValueArray = [...valueArray]
this.valueArray = [...valueArray] this.valueArray = [...valueArray]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册