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

              
                #app
  .Wrap
    fieldset
      legend Vue custom SELECT

      p selectedOption: 
        b {{selectedOption.name}}
      pre {{selectedOption}}

      //:selected="object"
      v-select(:options="options", @option="OnSelect")


              
            
!

CSS

              
                pre
  padding 1em
  background #f1f1f1
  float right
 
 
.V-select
  user-select none
  display inline-block
  position relative
  
  input
    background #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='12'><polygon points='0,0 12,0 6,12' fill='orange'/></svg>") 100% no-repeat;
    cursor pointer
  ul
    list-style none
    position absolute
    background #FFF
    width 100%
    box-shadow 0 .2em 1.4em 0 rgba(0, 0, 0, 0.2)
  li
    cursor pointer
    //color #477dca
    border-top 1px solid #EFEFEF
    
    padding 0 1em
    line-height: 2.4
    &.selected
      color #000
    &:hover
      background #f9f9f9

              
            
!

JS

              
                Vue.component("v-select", {
  template: `
  <div class="V-select">
    <input
      class="lg"
      :value="!selectedOption ? 'Please select an item' : selectedOption.name" readonly 
      @click="open=true" />
    <ul v-show="open">
      <li v-for="(option,i) in options"
        @click="updateOption(option,i)"
        :class="{selected:i==selectedItem}">
        {{ option.name }}
      </li>
    </ul>
  </div>
  `,
  props: {
    options: {
      type: [Array, Object]
    },
    selected: {}
  },
  data() {
    return {
      selectedOption: {},
      open: false,
      selectedItem: null
    };
  },
  created() {
    this.selectedOption = this.selected;
    document.body.addEventListener("click", this.close);
  },
  beforeDestroy() {
    document.body.removeEventListener("click", this.close);
  },
  methods: {
    updateOption(option, i) {
      this.selectedItem = i;
      this.selectedOption = option;
      this.open = false;
      this.$emit("option", option);
    },
    close(e) {
      //console.log(this.$el);
      if (!this.$el.contains(e.target)) this.open = false;
    }
  }
});


const options = [
  {
    name: "First Option",
    val: 1
  },
  {
    name: "Second Option",
    val: 2
  },
  {
    name: "Third Option",
    val: 3
  },
  {
    name: "Lorem ipsum",
    val: 4
  }
]

const vm = new Vue({
  el: "#app",
  data: {
    selectedOption: {},
    options: options
  },
  computed: {},
  methods: {
    OnSelect(option) {
      this.selectedOption = option;
    }
  },
  mounted() {}
});

              
            
!
999px

Console