Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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">
  <div>
    <div class="bg-indigo-500 p-5 h-screen">
      <div class="max-w-[768px] m-auto bg-white p-5">
        <h1 class="text-center text-2xl mb-4">Vue ToDoList</h1>
        <div class="flex">
          <input v-model="cacheTodo" type="text" class="w-full rounded-l-lg border-l-2 border-y-2 border-indigo-300 pl-4 focus:outline-indigo-500 focus:outline-none focus:outline-offset-0" placeholder="請輸入你的代辦事項" />
          <button @click="addTodo" class="w-[50px] h-[50px] border-0 bg-sky-500 hover:bg-sky-600 rounded-r-lg text-white transition duration-700">+</button>
        </div>
        <ul>
          <li v-for="todo in todoList" class="py-4">
            <label :class="todo.status ? 'line-through' : ''">
              <input @click="updateTodo" type="checkbox" :data-id="todo.id" />
              {{ todo.name }}
            </label>
          </li>
        </ul>
        <div class="flex justify-between items-center">
          <p>
            目前有 <span class="font-medium">{{ todoList.length }}</span> 個事項待完成
          </p>

          <button @click="remoteAllTodo" type="button" class="bg-red-300 p-2 rounded-md hover:bg-red-400 transition duration-700">Clear All Task</button>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                const app = Vue.createApp({
  setup() {
    const cacheTodo = Vue.ref('');
    const todoList = Vue.ref(JSON.parse(localStorage.getItem('todoList')) || []);

    const addTodo = () => {
      todoList.value.push({
        id: Date.now(),
        name: cacheTodo.value,
        status: false,
      })
      cacheTodo.value = '';
      setItem('todoList', todoList.value);
    };

    const updateTodo = (event) => {
      const { id } = event.target.dataset;
      todoList.value.forEach((todo) => {
        if(todo.id === Number(id)) {
          todo.status = !todo.status;
        }
      });
      setItem('todoList', todoList.value);
    }

    const remoteAllTodo = () => {
      todoList.value = [];
      setItem('todoList', todoList.value);
    };
    
    const setItem = (key, data) => {
      window.localStorage.setItem(key, JSON.stringify(data));
    }

    return {
      cacheTodo,
      todoList,
      addTodo,
      updateTodo,
      remoteAllTodo
    }
  }
});

app.mount('#app');
              
            
!
999px

Console