Skip to content

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

License

Notifications You must be signed in to change notification settings

FL3NKEY/vue-conditional-attrs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published