TodoList सोबत अॅप तयार करणे Vue.js

TodoList येथे अनुप्रयोग तयार करण्यासाठी विशिष्ट कोड उदाहरणांसह तपशीलवार चरण-दर-चरण मार्गदर्शक आहे Vue.js:

पायरी 1: प्रकल्प सेट अप करणे

Vue.js Vue CLI वापरून नवीन प्रकल्प तयार करून प्रारंभ करा. तुमचे टर्मिनल उघडा आणि खालील आदेश चालवा:

vue create todo-list-app

todo-list-app हे मूळ प्रकल्प संरचना आणि अवलंबनांसह नावाची नवीन निर्देशिका तयार करेल .

 

पायरी 2: तयार करणे TodoList Component

फोल्डरच्या आत src, नावाची एक नवीन फाइल तयार करा TodoList.vue. अर्जासाठी हा मुख्य घटक असेल TodoList.

मध्ये TodoList.vue:

<template>  
  <div>  
    <h1>TodoList</h1>  
    <!-- Render TodoItems here -->  
  </div>  
</template>  
  
<script>  
export default {  
  name: 'TodoList',  
  data() {  
    return {  
      todos: [  
        { id: 1, text: 'Learn Vue.js', completed: false },  
        { id: 2, text: 'Build a TodoList app', completed: false },  
        // Add more todo items here  
      ]  
    };  
  }  
};  
</script>  
  
<style>  
/* Add your custom styles here */  
</style>

 

पायरी 3: तयार करणे TodoItem Component

फोल्डरच्या आत src, नावाची एक नवीन फाइल तयार करा TodoItem.vue. वैयक्तिक टूडू आयटम रेंडर करण्यासाठी हा बालक घटक असेल.

मध्ये TodoItem.vue:

<template>  
  <div:class="{ 'completed': todo.completed }">  
    <input type="checkbox" v-model="todo.completed">  
    <span>{{ todo.text }}</span>  
    <button @click="deleteTodo">Delete</button>  
  </div>  
</template>  
  
<script>  
export default {  
  name: 'TodoItem',  
  props: ['todo'],  
  methods: {  
    deleteTodo() {  
      // Emit a custom event to notify the parent component(TodoList) to delete this todo item  
      this.$emit('delete', this.todo.id);  
    }  
  }  
};  
</script>  
  
<style scoped>  
.completed {  
  text-decoration: line-through;  
}  
</style>

 

चरण 4: अद्यतनित करत आहे TodoList Component

.vue च्या आत TodoList, v-for निर्देश वापरून s रेंडर करण्यासाठी टेम्पलेट विभाग अद्यतनित करा TodoItem.

मध्ये TodoList.vue:

<template>  
  <div>  
    <h1>TodoList</h1>  
    <div v-for="todo in todos":key="todo.id">  
      <TodoItem:todo="todo" @delete="deleteTodo"></TodoItem>  
    </div>  
    <!-- Add a form to add new todo items -->  
    <form @submit.prevent="addTodo">  
      <input type="text" v-model="newTodoText">  
      <button type="submit">Add Todo</button>  
    </form>  
  </div>  
</template>  
  
<script>  
import TodoItem from './TodoItem.vue';  
  
export default {  
  name: 'TodoList',  
  components: {  
    TodoItem  
  },  
  data() {  
    return {  
      todos: [  
        { id: 1, text: 'Learn Vue.js', completed: false },  
        { id: 2, text: 'Build a TodoList app', completed: false },  
        // Add more todo items here  
      ],  
      newTodoText: ''  
    };  
  },  
  methods: {  
    deleteTodo(id) {  
      // Find the index of the todo item in the array  
      const index = this.todos.findIndex(todo => todo.id === id);  
      // Remove the item from the array  
      this.todos.splice(index, 1);  
    },  
    addTodo() {  
      if(this.newTodoText) {  
        // Generate a unique ID for the new todo item  
        const newTodoId = this.todos.length + 1;  
        // Create a new todo item object and add it to the array  
        this.todos.push({  
          id: newTodoId,  
          text: this.newTodoText,  
          completed: false  
        });  
        // Clear the input field  
        this.newTodoText = '';  
      }  
    }  
  }  
};  
</script>  
  
<style>  
/* Add your custom styles here */  
</style>

 

पायरी 5: TodoList अर्जाची चाचणी करणे


अनुप्रयोगाची चाचणी घेण्यासाठी TodoList, "src/App.vue" फाइल उघडा आणि विद्यमान सामग्री खालील कोडसह पुनर्स्थित करा:

<template>  
  <div id="app">  
    <TodoList></TodoList>  
  </div>  
</template>  
  
<script>  
import TodoList from './TodoList.vue';  
  
export default {  
  name: 'App',  
  components: {  
    TodoList  
  }  
};  
</script>  
  
<style>  
/* Add your global styles here */  
</style>

 

पायरी 6: अनुप्रयोग चालवणे


टर्मिनलमध्ये खालील आदेश चालवून सर्व बदल जतन करा आणि विकास सर्व्हर सुरू करा:

npm run serve

ऍप्लिकेशन कृतीत आहे http://localhost:8080 हे पाहण्यासाठी आपल्या वेब ब्राउझरमध्ये भेट द्या. TodoList

हे उदाहरण a ची मूलभूत कार्यक्षमता दर्शवते

TodoList वापरून अनुप्रयोग Vue.js. वापरकर्ते टूडू आयटमची सूची पाहू शकतात, त्यांना पूर्ण झाले म्हणून चिन्हांकित करू शकतात, त्यांना हटवू शकतात आणि प्रदान केलेला फॉर्म वापरून नवीन आयटम जोडू शकतात. टूडू आयटमची स्थिती घटकामध्ये व्यवस्थापित केली जाते TodoList, तर प्रत्येक वैयक्तिक टूडू आयटम TodoItem घटक वापरून प्रस्तुत केला जातो.

कृपया लक्षात घ्या की ही एक सरलीकृत अंमलबजावणी आहे आणि तुम्ही तुमच्या विशिष्ट गरजांच्या आधारे अॅप्लिकेशन सानुकूलित आणि वाढवू शकता.