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="app" v-cloak class="container mx-auto flex items-center flex-col mt-10">
  <header class="text-center">
    <h1 class="text-5xl font-black">To do list on Vue.js</h1>
    <p class="text-xl font-semibold mb-8">You have {{ items.length }} tasks.</p>
  </header>

  <main class="mt-3">
    <label for="">
      <input id="add_item" type="text" placeholder="Add task" autofocus ref="addtask"
             class="bg-gray-200 focus:bg-white border-black border-solid border-2 px-2 py-1 w-full mb-4 hover:bg-white"
             @keyup.enter="addItem" />
    </label>

    <ul class="max-w-xs">
      <li v-for="(item, index) in items" class="my-4 flex items-center justify-end">
        <span v-if="! item.edit" class="px-2 py-1 mr-2 w-40 border-transparent border-solid border-2 hover:border-black" @click="enableEdit(index)">{{ item.title }}</span>
        <input v-else type="text" v-model="item.title" :ref="'task'" @keyup.enter="disableEdit(index)" @blur="disableEdit(index)" class="px-2 py-1 mr-2 w-40 border-black border-transparent focus:border-black border-solid border-2 focus:bg-white">
        <button class="border-black border-solid border-2 bg-orange-400 hover:bg-black hover:text-orange-400 focus:bg-black focus:text-orange-400 px-2 py-1 mr-2" @click="removeItem(index)">Delete</button>
        <button class="border-black border-solid border-2 bg-blue-400 hover:bg-black hover:text-blue-400 focus:bg-black focus:text-blue-400 px-2 py-1" @click="enableEdit(index)">Edit</button>
      </li>
    </ul>

    <p class="error px-2 py-1 rounded" v-if="isError">☝This task already exists.</p>
  </main>

  <div class="flex items-center bg-blue-500 text-white text-sm font-bold px-4 py-3 mt-12" role="alert">
  <svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M12.432 0c1.34 0 2.01.912 2.01 1.957 0 1.305-1.164 2.512-2.679 2.512-1.269 0-2.009-.75-1.974-1.99C9.789 1.436 10.67 0 12.432 0zM8.309 20c-1.058 0-1.833-.652-1.093-3.524l1.214-5.092c.211-.814.246-1.141 0-1.141-.317 0-1.689.562-2.502 1.117l-.528-.88c2.572-2.186 5.531-3.467 6.801-3.467 1.057 0 1.233 1.273.705 3.23l-1.391 5.352c-.246.945-.141 1.271.106 1.271.317 0 1.357-.392 2.379-1.207l.6.814C12.098 19.02 9.365 20 8.309 20z"/></svg>
  <p>PWA version <a href="https://alejandronarvaja.com/gha-vue-todo-exercise/" target="_blank" rel="noreferrer noopeneer" class="underline">here</a></p>
</div>

  <!-- <pre>{{ $data }}</pre> -->
</div>
              
            
!

CSS

              
                [v-cloak] {
  display: none;
}

*,
*::after,
*::before {
  transition: all 0.25s ease-out;
}

              
            
!

JS

              
                new Vue({
  el: "#app",
  data() {
    return {
      items: [
        {
          title: "HTML5",
          edit: false
        },
        {
          title: "CSS3",
          edit: false
        },
        {
          title: "JavaScript",
          edit: false
        }
      ],
      taskItem: "",
      isError: false
    };
  },
  methods: {
    addItem: function(e) {
      value = e.target.value;

      if (value === "") {
        return false;
      }

      if (this.itemExist(value) === true) {
        let repeated = [].filter.call(
          document.getElementsByTagName("span"),
          function(span) {
            return span.textContent === value;
          }
        );
        this.isError = true;
        repeated[0].classList.add("bg-orange-300");
        return false;
      }

      this.isError = false;
      e.target.value = "";
      this.items.push({
        title: value,
        edit: false
      });

      let repeatedClasses = document.querySelectorAll(".bg-orange-300");
      for (let repeatedClass of repeatedClasses) {
        repeatedClass.classList.remove("bg-orange-300");
      }
    },
    removeItem: function(index) {
      this.items.splice(index, 1);
      this.$refs.addtask.focus();
    },
    enableEdit: function(index) {
      this.items[index].edit = true;
      this.$nextTick(() => {
        let input = this.$refs.task[0];
        input.focus();
      });
    },
    disableEdit: function(index) {
      this.items[index].edit = false;
    },
    itemExist: function(value) {
      for (var i = 0; i < this.items.length; i++) {
        if (this.items[i].title === value) {
          return true;
        }
      }

      return false;
    }
  }
});

              
            
!
999px

Console