Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (35 sloc) 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';
    },
  },
});
You can’t perform that action at this time.