How to do Vue 3 Composition API CRUD with Tailwindcss

Vue 3 Composition API CRUD
Spread the love

Composition API is the main feature of Vue3. Hello Developers, How are you doing? Are you looking for how to make a by Vue 3 Composition API? In this tutorial, I will show how to make a CRUD using Vue composition API. For UI design I will use Tailwindcss. If you don’t how to add Tailwindcss in the Vue application you can read this blog How to add Tailwindcss in Vue Js Application

How to do Vue 3 Composition API CRUD with Tailwindcss

Vue 3 Composition API CRUD
Vue 3 CRUD

Create a vue project using vue CLI

Well, First install a Vue application using Vue CLI. Run this command in your terminal where you want to install your project. Make sure that you have installed Vue CLI before.

vue create composition-api

Well, now you have to wait a couple of minutes for installing a fresh vue project. But remember you have to select some options as a need for your project.

Check Vue CLI version

Note: before run vue create a project this command you can check your vue version by this command.

vue --version //output : @vue/cli 4.5.12

Make a Vue Component for CRUD Operation

Well, Now make a Component composition-api/src/views/Todo.vue. Copy the following code in your component.

  <div class="container mx-auto">
    <h1 class="mt-8 text-2xl text-center mb-3">Todos</h1>
    <hr class="border m-3 ">
    <div class="mt-3">
      <div class="grid grid-cols-12 gap-4">
        <div class="col-span-6 "
             style="height: 500px">
         <div v-if="todos.length" class="space-y-4 px-1">
              <div v-for="(todo,index) in todos" :key="todo"
               class="p-8 bg-white shadow-md rounded flex items-center justify-between"
                :class="{'bg-green-200': todo.isDone}"
              <div>{{ todo.title }}</div>
              <div class="text-gray-500 text-sm">{{ todo.time }}</div>
            <div class="space-x-2">
              <button class="px-2 text-red-600"
                      title="Remove todo">&times;</button>
              <button v-if="!todo.isDone"
                      class="px-2 text-green-600"
                      title="Mark as done">&check;</button>
              <button  v-if="todo.isDone"
                      class="px-2 text-orange-600"
                      title="Mark as undone">&#8630;</button>
          <div v-else
               class="px-8 py-16 bg-white text-gray-700 shadow-md rounded text-sm">
            You dont have any task to do.

        <div class="col-span-6">
          <div class="p-8 bg-white shadow-md rounded">
            <h2 class="text-xl">Add a todo</h2>
            <input type="text"
                   placeholder="Enter your Task "
                   class="p-2 mt-4 border rounded w-full">


In the Script Portion Paste belows code

import { reactive, ref } from '@vue/reactivity'
export default {
        const item = ref(null)
        let todos = reactive([
            {id:1,title : 'One',isDone : true,time : new Date().toString()}
        const addNewItem = () => {
                id : Math.floor(Math.random() * 100),
                title : item.value,
                isDone : false,
                time : new Date().toString()
            item.value = ''
        const taskDone = (index) => {
            todos[index].isDone = true
        const taskUndo = (index) => {
            todos[index].isDone = false
        const removeTask = (index) => {
            if(confirm('Are you sure ?')){
        const print = (e) => console.log(e)
        return {

Well, Our script and template portions have been done. Now time to test our project. Run this code in terminal yarn run dev

Hope it will help you.

Read More : 10 PHP Interview Questions You should know

Spread the love

About Anisur Rahman Shahin

Hello. My name is Shahin. I'm a tech enthusiast guy. Personally, I’m an Optimistic and always in hurry kinda person. I'm a freelance web developer. I am working at Zakir Soft as Laravel Developer. My Portfolio website:

View all posts by Anisur Rahman Shahin →

Leave a Reply

Your email address will not be published.