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

              
                <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>

<div id="app">
  <div class="edit-form-list">
    <transition-group name="fade" tag="div">
      <history-item v-on:add-history-item="addHistory" v-on:delete-history-item="deleteHistory" v-on:move-history-item="moveHistory" v-for="(item, index) in histories" :key="item.id" :index="index" :item="item"></history-item>
    </transition-group>
    <el-button @click="addHistory" icon="el-icon-circle-plus-outline">Add</el-button>
    <el-button @click="sortHistory" icon="el-icon-sort-down">Sort</el-button>
    <el-button @click="setDefaultHistories" icon="el-icon-refresh">Reset</el-button>
  </div>
</div>

<template id="history-item">
  <div class="item">
        <el-input 
                  placeholder="2000"
                  v-model="item.year"
                  type="number"
                  min="1900"
                  max="2999"
                  ref="year"></el-input><span>年</span>
        <el-input 
                  placeholder="12"
                  v-model="item.month"
                  type="number"
                  min="1"
                  max="12"
                  ref="month">
        </el-input><span>月</span>
      <el-input                 placeholder="description"
                v-model="item.description"
                ref="desc"></el-input>
    <el-dropdown class="history-form-action"
                 trigger="click"
                 @command="handleCommand">
      <el-button icon="el-icon-more-outline"></el-button>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="addAbove">
          <i class="el-icon-caret-top"></i>
          Add Above   
        </el-dropdown-item>
        <el-dropdown-item command="addBelow">
          <i class="el-icon-caret-bottom"></i> 
          Add Below
        </el-dropdown-item>
        <el-dropdown-item command="moveUp">
          <i class="el-icon-arrow-up"></i>
          Move Up
        </el-dropdown-item>
        <el-dropdown-item command="moveDown">
          <i class="el-icon-arrow-down"></i>
          Move Down
        </el-dropdown-item>
        <el-dropdown-item command="duplicate">
          <i class="el-icon-circle-plus"></i>
          Duplicate
        </el-dropdown-item>
        <el-dropdown-item command="delete"> 
          <i class="el-icon-delete"></i>
          Delete
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
</div>
</template>
              
            
!

CSS

              
                #app .el-input{
  width:auto;
}
#app .el-input__inner{
  width:auto;
}
.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
.item{
  margin:0 0 10px;
}
              
            
!

JS

              
                Vue.component("history-item", {
  props: ["item", "index"],
  template: "#history-item",
  methods: {
    handleCommand: function(command) {
      if (command === "addAbove") {
        this.$emit("add-history-item", { index: this.index });
      } else if (command === "addBelow") {
        this.$emit("add-history-item", { index: this.index + 1 });
      } else if (command === "delete") {
        this.$emit("delete-history-item", this.index);
      } else if (command === "duplicate") {
        this.$emit("add-history-item", { index: this.index, item: this.item });
      } else if (command === "moveUp") {
        this.$emit("move-history-item", {
          index: this.index,
          to: "up"
        });
      } else if (command === "moveDown") {
        this.$emit("move-history-item", {
          index: this.index,
          to: "down"
        });
      }
    }
  }
});

new Vue({
  el: "#app",
  data: function() {
    return {
      defaultHistories: [
        {
          year: 2001,
          month: 2,
          description: "desc2",
          id: this.uuidv4()
        },
        {
          year: 2000,
          month: 1,
          description: "desc1",
          id: this.uuidv4()
        },

        {
          year: 2002,
          month: 3,
          description: "desc3",
          id: this.uuidv4()
        }
      ],
      histories: [
        {
          year: 2000,
          month: 1,
          description: "",
          id: this.uuidv4()
        }
      ]
    };
  },
  methods: {
    uuidv4: function() {
      return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
        (
          c ^
          (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
        ).toString(16)
      );
    },
    createHistoryItem: function(item) {
      if (!item) {
        item = {};
      }
      var newItem = {
        year: item.year || "",
        month: item.month || "",
        description: item.description || "",
        id: this.uuidv4()
      };
      return newItem;
    },
    addHistory: function(params) {
      const index = typeof params.index != "undefined" ? params.index : null;
      const item = params.item || null;
      const newHistoryItem = this.createHistoryItem(item);
      if (typeof index === "number") {
        this.histories.splice(index, 0, newHistoryItem);
      } else {
        this.histories.push(newHistoryItem);
      }
    },
    moveHistory: function(params) {
      const fromIndex = params.index;
      const to = params.to;
      if (fromIndex === 0 && to === "up") {
        console.log("first item skip");
        return;
      }
      if (fromIndex + 1 === this.histories.length && to === "down") {
        console.log("last item skip");
        return;
      }
      if (to === "up") {
        this.histories.splice(
          fromIndex - 1,
          2,
          this.histories[fromIndex],
          this.histories[fromIndex - 1]
        );
      } else if (to === "down") {
        this.histories.splice(
          fromIndex,
          2,
          this.histories[fromIndex + 1],
          this.histories[fromIndex]
        );
      } else {
        console.log('param "to" must be "up" or "down"');
      }
    },
    sortHistory: function() {
      this.histories = _.orderBy(
        this.histories,
        ["year", "month"],
        ["asc", "asc"]
      );
    },
    deleteHistory: function(index) {
      this.histories.splice(index, 1);
    },
    setDefaultHistories: function() {
      this.histories = _.cloneDeep(this.defaultHistories);
    }
  },
  mounted: function() {
    this.setDefaultHistories();
  }
});

              
            
!
999px

Console