cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
                  <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>
            
          
!
            
              

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console