Skip to content

Commit

Permalink
feat: 优化组件默认值问题
Browse files Browse the repository at this point in the history
  • Loading branch information
weishuodan committed Nov 17, 2023
1 parent 4e6f1e5 commit 0152f57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components/license-plate/demo/cases/demo0.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default {
},
mounted() {
// setTimeout(()=>{
// this.defaultValue = '2333'
// },3000)
// this.defaultValue = '23338888888'
// },10000)
},
methods: {},
}
Expand Down
15 changes: 9 additions & 6 deletions components/license-plate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,17 @@ export default {
defaultValue: {
handler(newVal) {
if (newVal !== '') {
const defaultValueArray =
this.defaultValue.split('').length > 8
? this.defaultValue.split('').splice(0, 8)
: this.defaultValue.split('')
const defaultValueArray = this.defaultValue.split('')
const keyArrayCopy = JSON.parse(JSON.stringify(this.keyArray))
defaultValueArray.forEach((item, index) => {
keyArrayCopy[index] = item
keyArrayCopy.forEach((item, index) => {
if (defaultValueArray[index]) {
keyArrayCopy[index] = defaultValueArray[index]
} else {
keyArrayCopy[index] = ''
}
})
this.keyArray = keyArrayCopy
}
},
Expand Down

0 comments on commit 0152f57

Please sign in to comment.