vue-merge-data

Intelligently merge data for Vue render functions.
2,591 1
Install
npm install vue-merge-data
Latest Version:0.2.1
License:MIT
Last Updated:May 17, 2018
Links: GitHub  ·  npm
Maintainer: funch

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) Strategy Example
staticClass append target: { staticClass: 'button' }
source: { staticClass: 'button--mini' }
result: { staticClass: 'button button--mini' }
attrs, domProps, scopedSlots, staticStyle, props, hook, transition override target: { attrs: { type: 'reset' } }
source: { attrs: { type: 'submit' } }
result: { attrs: { type: 'submit' } }
class, style, directives, on, nativeOn expand target: { class: 'button', on: { click: FN1 } }
source: { class: { mini: true }, on: { click: FN2 } }
result: { class: ['button', { mini: true }], on: { click: [FN2, FN1] } }
others: slot, key... override target: { slot: 'icon' }
source: { slot: 'image' }
result: { slot: 'image' }

Related Packages

@andresouzaabreu/vue-data-table

A Vue plugin that adds advanced features to an HTML table

24,586 129
@barbosa89/vue-table

Classical data table

1,178 0
epage-iview

epage render package based on iview component library

1,080 24
apexcharts

A JavaScript Chart Library

86,943,728 15,180
vue-peity

A Vue version of an excellent peity library for beautiful mini graphs.

43,580 63

Version History

Version Released License
0.2.1 MIT
0.2.0 MIT
0.1.3 MIT
0.1.2 MIT
0.1.1 MIT