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="representation">

      <div v-if="stateReady">
        <ul >


          <li v-for="item in items">
            <h3 v-on:click="edit($index)" >{{item.name}}</h3>
            <p>{{item.description}}</p>
            <button v-on:click="delete($index)">Delete</button>
            <br>
          </li>



        </ul>
        <div>
          <input type="text" id="name" v-model="itemV.name" placeholder="Name">
          <input type="text" id="description" v-model="itemV.description" placeholder="Description">
          <button v-on:click="add" v-if="stateAdding">Add</button>

          <button v-on:click="save" v-if="stateEditing">Save</button>
          <button v-on:click="cancel" v-if="stateEditing">Cancel</button>
        </div>
      </div>



    </div>
    <script type='text/javascript' src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.16/vue.min.js"></script>
              
            
!

CSS

              
                
              
            
!

JS

              
                

var app = new Vue({
  el: '#representation',
  ready () {

  },

  data: {
    // input field view binding
    itemV: {name :'', description : ''},

    // model
    items: [
      { name: 'Item 1 name',
        description: 'Item 1 description'
      }
    ],
    openedEditor: false,
    editingIndex: false


  },

  // state
  computed: {
    stateReady: function () {
      return true;
    },
    stateAdding () {
      return (!this.openedEditor)
    },
    stateEditing () {
      return (this.openedEditor)
    }

  },

  methods: {
    modelPresent (data) {
      data = data || {} ;
      // if (data.item !== undefined ) {
      if (data.name !== undefined && data.description !== undefined) {
        // adding item
        if (data.deleteAtIndex === undefined && data.openedEditor === false ) {
          this.items.push({name :data.name, description : data.description});
          this.itemV = {name :'', description : ''};
        }

        // start editing
        if (data.openedEditor === true && data.index !== undefined) {
          this.openedEditor = data.openedEditor;

          //populate view fields with item data that we decided to edit
          this.itemV = {name :data.name, description : data.description};

          // save the index for if we decide to save
          this.editingIndex = data.index;

        }
        // saving edited  item
        if (data.openedEditor === true && data.index === undefined) {

          this.items[this.editingIndex].name = data.name;
          this.items[this.editingIndex].description = data.description;

          // reset to adding state
          this.editingIndex = false;
          this.openedEditor = false;
          this.itemV = {name :'', description : ''};
        }


      }

      // canceling edit
      if (data.canceledEdit === true) {
        this.openedEditor = false;
        this.itemV = {name :'', description : ''};
        this.editingIndex = false;
      }

      // removing item
      if (data.deletedItemIndex !== undefined) {
        this.items.splice(data.deletedItemIndex, 1);
      }

      app.nextAction();
    },

    // view helper methods, called from the view they get data from the view and pass it to the appropriate action
    add () {
      var data = this.formFields();
      actions.add(data)
    },
    edit (index) {
      // grab the item to display it in the edit fields
      item = this.items[index];
      actions.edit({name: item.name, description: item.description,index: index});
    },
    save () {

      var data = this.formFields();
      actions.save(data);
    },
    delete (index) {

      actions.delete({deletedItemIndex: index})
    },
    cancel() {
      actions.cancel({});
    },


    nextAction: function () {

    },

    formFields(data) {
      data = data || {} ;
      data.name = document.getElementById('name').value;
      data.description = document.getElementById('description').value;
      return data
    }

  }
});




var actions = {} ;

actions.edit = function(data, present) {
    present = present || app.modelPresent ;
    data.openedEditor = true;

    present(data) ;
    return false ;
} ;

actions.add = function(data, present) {
  present = present || app.modelPresent ;

  data.openedEditor = false;
  present(data) ;
  return false ;
};

actions.save = function(data, present) {
    present = present || app.modelPresent ;

    data.openedEditor = true;
    present(data) ;
    return false ;
} ;

actions.delete = function(data, present) {
    present = present || app.modelPresent ;
    present(data) ;
    return false ;
} ;

actions.cancel = function(data, present) {
    present = present || app.modelPresent ;
    data.canceledEdit = true;
    present(data) ;
    return false ;
} ;

              
            
!
999px

Console