Skip to content

Commit

Permalink
fix(useVModel): returning undefined on false values (#1557)
Browse files Browse the repository at this point in the history
* fix(useVModel): returning undefined on false values

* use ?? instead
  • Loading branch information
wheatjs committed May 4, 2022
1 parent eaf4553 commit 0f3ddca
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/core/useVModel/index.test.ts
Expand Up @@ -13,6 +13,11 @@ describe('useVModel', () => {
expect(data.value).toBe(defaultValue)
})

it('should work with boolean', () => {
const data = useVModel({ [defaultKey]: false })
expect(data.value).toBe(false)
})

it('should work with arguments', () => {
const props = {
...defaultProps(),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/useVModel/index.ts
Expand Up @@ -86,7 +86,7 @@ export function useVModel<P extends object, K extends keyof P, Name extends stri
else {
return computed<P[K]>({
get() {
return props[key!] || defaultValue!
return props[key!] ?? defaultValue!
},
set(value) {
_emit(event, value)
Expand Down

0 comments on commit 0f3ddca

Please sign in to comment.