1 |
|
2 |
|
3 | import config from 'core/config'
|
4 |
|
5 | import {
|
6 | warn,
|
7 | isObject,
|
8 | toObject,
|
9 | isReservedAttribute,
|
10 | camelize,
|
11 | hyphenate
|
12 | } from 'core/util/index'
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export function bindObjectProps (
|
18 | data: any,
|
19 | tag: string,
|
20 | value: any,
|
21 | asProp: boolean,
|
22 | isSync?: boolean
|
23 | ): VNodeData {
|
24 | if (value) {
|
25 | if (!isObject(value)) {
|
26 | process.env.NODE_ENV !== 'production' && warn(
|
27 | 'v-bind without argument expects an Object or Array value',
|
28 | this
|
29 | )
|
30 | } else {
|
31 | if (Array.isArray(value)) {
|
32 | value = toObject(value)
|
33 | }
|
34 | let hash
|
35 | for (const key in value) {
|
36 | if (
|
37 | key === 'class' ||
|
38 | key === 'style' ||
|
39 | isReservedAttribute(key)
|
40 | ) {
|
41 | hash = data
|
42 | } else {
|
43 | const type = data.attrs && data.attrs.type
|
44 | hash = asProp || config.mustUseProp(tag, type, key)
|
45 | ? data.domProps || (data.domProps = {})
|
46 | : data.attrs || (data.attrs = {})
|
47 | }
|
48 | const camelizedKey = camelize(key)
|
49 | const hyphenatedKey = hyphenate(key)
|
50 | if (!(camelizedKey in hash) && !(hyphenatedKey in hash)) {
|
51 | hash[key] = value[key]
|
52 |
|
53 | if (isSync) {
|
54 | const on = data.on || (data.on = {})
|
55 | on[`update:${key}`] = function ($event) {
|
56 | value[key] = $event
|
57 | }
|
58 | }
|
59 | }
|
60 | }
|
61 | }
|
62 | }
|
63 | return data
|
64 | }
|