0.2.1 • Published 6 years ago

vue-merge-data v0.2.1

Weekly downloads
28
License
MIT
Repository
github
Last release
6 years ago

vue-merge-data

npm npm downloads Travis minified size minzipped size license

Intelligently merge data for Vue render functions.

yarn add vue-merge-data

CDN: jsDelivr | UNPKG (Avaliable as window.VueMergeData)

Usage

First, import it:

import mergeData from 'vue-merge-data'

Then, use it in Vue render functions:

// Normal component
export default {
  name: 'primary-button',
  props: { mini: Boolean },
  render(h) {
    return h('base-button', mergeData(this.$vnode.data, {
      attrs: {
        type: 'primary',
        mini: this.mini
      },
      on: {
        click: () => {}
      }
    }), this.$slots.default)
  }
}

// Functional component
export default {
  name: 'primary-button',
  functional: true,
  props: { mini: Boolean },
  render(h, { props, data, children }) {
    return h('base-button', mergeData(data, {
      attrs: {
        type: 'primary',
        mini: props.mini
      },
      on: {
        click: () => {}
      }
    }), children)
  }
}

Merging strategies

Prop(s)StrategyExample
staticClassappendtarget: { staticClass: 'button' }source: { staticClass: 'button--mini' }result: { staticClass: 'button button--mini' }
attrs, domProps, scopedSlots, staticStyle, props, hook, transitionoverridetarget: { attrs: { type: 'reset' } }source: { attrs: { type: 'submit' } }result: { attrs: { type: 'submit' } }
class, style, directives, on, nativeOnexpandtarget: { class: 'button', on: { click: FN1 } }source: { class: { mini: true }, on: { click: FN2 } }result: { class: ['button', { mini: true }], on: { click: [FN2, FN1] } }
others: slot, key...overridetarget: { slot: 'icon' }source: { slot: 'image' }result: { slot: 'image' }
0.2.1

6 years ago

0.2.0

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago