6ad5d108596143aada76d004eb9dd9e073f970c20a3661c992741bb5f4fcfee103a2c69fc086f71c2058dacff662ea620e00095e9c82d75b5102ce080c622c 1.5 KB

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