Nothing's plumb meaningless
Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

vue-conditional-attrs

0.0.3 • Public • Published

vue-conditional-attrs

A Vue.js component for conditional rendering attributes and directives.

Install

Via npm npm instal vue-conditional-attrs --save

import VueConditionalAttrs from 'vue-conditional-attrs';
//OR
var VueConditionalAttrs = require('vue-conditional-attrs');
 
Vue.use(VueConditionalAttrs);

Via script tag

<script src="/node_modules/vue-conditional-attrs/dist/vue-conditional-attrs.min.js"></script>

Usage

Once installed you have access to cn-attrs component.

<cn-attrs :tag="tag" :attrs="attrs" :directives="directives" :on="on"></cn-attrs>

Tag name

Accept tag name or component name.
Type: String
Attribute: tag
Default: div

<cn-attrs tag="tag name or component name"></cn-attrs>
<!---->
<cn-attrs tag="h1"></cn-attrs>
<cn-attrs tag="my-awesome-component"></cn-attrs>

Attributes

Accept object of attributes.
Type: Object
Attribute: attrs

<cn-attrs :attrs="attrs"></cn-attrs>
//Vue instance
data: function() {
  return {
    attrs: {
      'attribute-name': {
        value: /* value */,
        if: Boolean
      }
    }
  }
}
//Vue instance

OR

//Vue instance
data: function() {
  return {
    attrs: {
      'attribute-name': Boolean /* or value */
    }
  }
}
//Vue instance

Directives

Accept object of directives.
Type: Object
Attribute: directives

<cn-attrs :directives="directives"></cn-attrs>
//Vue instance
data: function() {
  return {
    directives: {
      'directive-name': {
        value: /* value */,
        if: Boolean
      }
    }
  }
}
//Vue instance

OR

//Vue instance
data: function() {
  return {
    directives: {
      'directive-name': Boolean
    }
  }
}
//Vue instance

Listeners

Accept object of listeners.
Type: Object
Attribute: on

<cn-attrs :on="listeners"></cn-attrs>
//Vue instance
data: function() {
  return {
    listeners: {
      'listener-name': { //example: click
        event: Function,
        if: Boolean
      }
    }
  }
}
//Vue instance

OR

//Vue instance
data: function() {
  return {
    listeners: {
      'listener-name': Function /* or false */
    }
  }
}
//Vue instance

Install

npm i vue-conditional-attrs

DownloadsWeekly Downloads

4

Version

0.0.3

License

MIT

Last publish

Collaborators

  • avatar