Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="pen">
  <vue-checkbox v-for="field in data" :value-model.sync="field.value" :label-model.sync="field.name" value-true="chicken" value-false="potato"/>
</div>

<template id="vue-checkbox">
  <div class="vue-checkbox-wrapper">
    <label class="vue-checkbox-label" v-text="label"></label>
    <div class="vue-checkbox" 
         v-bind:class="{'vue-checkbox_checked':checked}"
         @click="click">
      <div class="vue-checkbox-inner">
            <div class="vue-checkbox-inner-highlight"></div>
      </div>
    </div>
  </div>
</template>
              
            
!

CSS

              
                .vue-checkbox-label {
  position: relative;
  top: -1.75em;
}

.vue-checkbox {
  display: inline-block;
  box-sizing: content-box;
  width: 4em;
  height: 2em;
  border-radius: 2em;
  border: .2em solid rgb(237, 156, 17);
/*   background: rgb(207, 61, 42); */
  margin: 1em 0;
}

.vue-checkbox-inner {
  box-sizing: border-box;
  position: relative;
  top: 0.125em;
  left: 0.25em;
  width: 1.75em;
  height: 1.75em;
  border-radius: 2em;
  border: .5em solid rgb(237, 156, 17);
  background: rgb(207, 61, 42);
  transition: all 0.25s;
  transition-timing-function: ease-out;
}

.vue-checkbox_checked .vue-checkbox-inner{
  left: 2em;
  background: rgb(106, 164, 65);
}
              
            
!

JS

              
                var VueCheckboxComponent = Vue.extend({
  name: 'vue-checkbox',
  template: "#vue-checkbox",
  props:['valueModel', 'labelModel', 'valueTrue', 'valueFalse'],
  data: function () {
    return {};
  },
  methods: {
    isChecked: function () {
      return this.valueModel == this.trueVal;
    },
    click: function () {
      if(this.valueModel == this.trueVal) {
        this.valueModel = this.falseVal;
      }else{
        this.valueModel = this.trueVal;
      }
    }
  },
  computed: {
    value: function () {
      if(this.isChecked()) {
        return this.trueVal;
      }else{
        return this.falseVal;
      }
    },
    checked: function () {
      return this.isChecked();
    },
    trueVal: function () {
      if(typeof this.valueTrue == 'undefined'){
        return true;
      }else {
        return this.valueTrue;
      }
    },
    falseVal: function () {
      if(typeof this.valueFalse == 'undefined'){
        return false;
      }else {
        return this.valueFalse;
      }
    },
    label: function () {
      if(typeof this.labelModel == 'undefined'){
        return "";
      }else {
        return this.labelModel;
      }
    }
  }
});

// Register Component with Vue Instance
Vue.component('vue-checkbox', VueCheckboxComponent);

var GlobalVue = new Vue({
  el: '#pen',
  data: function () {
    return {
      data: [
        {
          name: "Field 1",
          value: 'potato'
        },
        {
          name: "Field 2",
          value: 'chicken'
        },
        {
          name: "Field 3",
          value: 'potato'
        },
        {
          name: "Field 4",
          value: 'potato'
        }
      ]
    }
  }
});
              
            
!
999px

Console