Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 617 Bytes

v-label.md

File metadata and controls

44 lines (35 loc) · 617 Bytes

v-label

// directives/label.js

const label = {
  update(value) {
    let className = this.el.className;
    if (value) {
      className = `${className} label label-success`;
    } else {
      className = `${className} label label-danger`;
    }

    this.el.className = className;
  },
};

//
Vue.directive('label', label);

Demo

<span v-label="status">{{ txt }}</span>
new Vue({
  el: '...', // omitted 
  data: {
    status: false,
  };
  computed() {
    txt() {
      return this.status ? 'Active' : 'Inactive';
    },
  },
});