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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              <p>This one does not have <code>v-bind:keys</code> set. Notice the incorrect DOM, color, and structure when sorting. Works when changing a few innocuous things, like if using <code>&lt;span&gt;</code>s instead of <code>&lt;div&gt;</code>s in the $slots or wrapping <code>render-vnodes</code> with an extra <code>&lt;div&gt;</code></p>
<div id="app">
  <button @click="$root.$emit('sort1')">Toggle Sorting
  </button>
  <color-izer>
    <div>GREEN 2</div>
    <div>RED 1</div>
    <div>GREEN 1</div>
    <div>RED 2</div>
    <div>RED 3</div>
    <div>GREEN 3</div>
  </color-izer>
  <p>This one has <code>v-bind:keys</code>. It works fine</p>
  <button @click="$root.$emit('sort2')">Toggle Sorting
  </button>
  <color-izer set-keys="true">
    <div>GREEN 2</div>
    <div>RED 1</div>
    <div>GREEN 1</div>
    <div>RED 2</div>
    <div>RED 3</div>
    <div>GREEN 3</div>
  </color-izer>
</div>
            
          
!

CSS

            
              html, body{
  max-width: 800px;
}
            
          
!

JS

            
              Vue.component("render-vnodes", {
  functional: true,
  render: function(createElement, ctx){
    return createElement("div", {}, ctx.props.vnodes);
  }
});

Vue.component("color-izer", {
  template: "<div><div style='display:inline-block;border:1px solid black;padding:4px;'>SORTED? {{sorted}}</div><br>" +
  "<render-vnodes v-if='sorted' :vnodes='nodesForColor(\"r\")'></render-vnodes>" + 
  "<render-vnodes v-if='sorted' :vnodes='nodesForColor(\"g\")'></render-vnodes>" + 
  "<slot v-if='!sorted'></slot></div>",
  mounted: function(){
    if(this.setKeys) {
      this.$slots.default.forEach(function(vnode, index){
        vnode.key = index;
      });
    }
    this.$slots.default
        .filter(function(a){return !!a.children;})
        .forEach(function(vnode){
          var color = vnode.children[0].text[0].toLowerCase();
          var style = {
            backgroundColor: color === "r" ? "#DD7777" : "#77DD77",
            display: "inline-block",
            padding: "5px",
            fontFamily: "Arial"
          };
          vnode.data = vnode.data || {};
          vnode.data.style = style;
        })
    var self = this;
    this.$root.$on(this.setKeys ? "sort2" : "sort1", function(){
      self.sorted = !self.sorted;
      self.$forceUpdate();
    });
  },
  props: ["setKeys"],
  data: function(){
    return {sorted: false};
  },
  methods: {
    nodesForColor: function(color){
      var self = this;
      return this.$slots.default.slice()
        .filter(function(a){return !!a.children;})
        .filter(function(vnode){
          return vnode.children[0].text[0].toLowerCase() === color;
        });
    }
  }
});
new Vue({
  el: "#app"
});
            
          
!
999px

Console