-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vue): fix format vue3 h function props (#2609)
- Loading branch information
1 parent
26861a8
commit e2dfc0b
Showing
3 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { formatVue3VNodeData } from '../utils/formatVNodeData' | ||
|
||
test('valid formatVNodeData', () => { | ||
const onClick = () => {} | ||
const ondblclick = () => {} | ||
|
||
const vNodeData = { | ||
class: [{ bar: false }, { 'test-component': true }], | ||
style: { | ||
border: '4px solid red', | ||
padding: '20px', | ||
borderRadius: '10px', | ||
}, | ||
attrs: { | ||
id: 'foo', | ||
}, | ||
props: { | ||
value: 'leader', | ||
user: { | ||
name: '张三', | ||
age: 18, | ||
sex: 1, | ||
}, | ||
}, | ||
domProps: { | ||
innerHTML: 'innerHTML - baz', | ||
}, | ||
on: { | ||
click: onClick, | ||
}, | ||
nativeOn: { | ||
dblclick: ondblclick, | ||
}, | ||
} | ||
|
||
const vue3VNodeData = { | ||
class: [{ bar: false }, { 'test-component': true }], | ||
style: { | ||
border: '4px solid red', | ||
padding: '20px', | ||
borderRadius: '10px', | ||
}, | ||
id: 'foo', | ||
value: 'leader', | ||
user: { | ||
name: '张三', | ||
age: 18, | ||
sex: 1, | ||
}, | ||
innerHTML: 'innerHTML - baz', | ||
onClick, | ||
ondblclick, | ||
} | ||
|
||
expect(formatVue3VNodeData(vNodeData)).toEqual(vue3VNodeData) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { each } from '@formily/shared' | ||
|
||
type VNodeData = Record<string, any> | ||
|
||
export const formatVue3VNodeData = (data: VNodeData) => { | ||
const newData = {} | ||
each(data, (value, key) => { | ||
if (key === 'on' || key === 'nativeOn') { | ||
if (value) { | ||
each(value, (func, name) => { | ||
const eventName = `on${ | ||
key === 'on' ? name[0].toUpperCase() : name[0] | ||
}${name.slice(1)}` | ||
newData[eventName] = func | ||
}) | ||
} | ||
} else if (key === 'attrs' || key === 'props' || key === 'domProps') { | ||
Object.assign(newData, value) | ||
} else { | ||
newData[key] = value | ||
} | ||
}) | ||
return newData | ||
} |