Update the image "done.img" when the todoapp is clicked using VueJS

I am currently practicing with VueJs and I would like to be able to click on the 'awaiting.img' image, so that the 'done.img' image will appear instead of the other one. Currently, every time I click on the 'awaiting.img' image, it appears for every list item.

I know I could fix this using vanilla JavaScript or another framework instead of Vuejs, but I am looking for ideas on how to fix it specifically with Vue.

Thank you all :)

You can check out the project on GitHub pages: LINK
This is the GitHub repository: link

const {
  createApp
} = Vue

createApp({
  data() {
    return {
      done: false,
      errorEmpty: false,
      errorMinChar: false,
      newTask: '',
      tasks: [{
          text: 'Fare i compiti',
          done: false
        },
        {
          text: 'Fare la spesa',
          done: true
        },
        {
          text: 'Fare il bucato',
          done: false
        }
      ]
    }
  },
  methods: {
    addNew() {
      if (this.newTask == "") {
        this.errorEmpty = true;
        this.errorMinChar = false;
      } else if (this.newTask.length < 3) {
        this.errorMinChar = true;
        this.errorEmpty = false;

      } else {
        this.errorEmpty = false;
        this.errorMinChar = false;
        this.tasks.push({
          text: this.newTask
        });
      }
      this.newTask = "";
    },
    deleteTask(indice) {
      if (confirm('Are you sure you want to delete?')) {
        this.tasks.splice(indice, 1);
      }
    },
    doneFunc(indice) {
      this.done = true;
      console.log(indice);

    }
  },
  mounted() {

  }
}).mount("#app")
<li v-for="(task,i) in tasks">
  {{task.text}}
  <div class="btnSection">
    <img src="img/awaiting.svg" alt="" @click="doneFunc(i)">
    <img src="img/done.svg" alt="" v-if="done">
    <button type="button" class="btn-close mx-2" aria-label="Close" @click="deleteTask(i)"></button>

  </div>

</li>

Answer №1

update the following:

<img src="img/done.svg" alt="" v-if="done">

to this:

<img src="img/done.svg" alt="" v-if="task.done">

and in your doneFunc:

doneFunc(indice){
    this.tasks[indice].done = true;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

what is the mechanism behind __dirname in Node.js?

Node.js is a new technology for me and I recently discovered the "__dirname" feature which is really useful for obtaining the absolute path of the script. However, I am intrigued by how it works and how it manages to interpret the directory structure. De ...

Is there a way to find the JavaScript Window ID for my current window in order to utilize it with the select_window() function in

I'm currently attempting to choose a recently opened window while utilizing Selenium, and the select_window() method necessitates its WindowID. Although I have explored using the window's title as recommended by other sources, and enabled Seleni ...

Displaying Errors from Controllers in React Hook Forms

Currently, I am attempting to generate required errors for my input element that is enclosed within a Controller component from react-hook-form version 7. The Input consists of a Material-UI TextField structured like this; <Controller ...

Encountering an issue in Laravel 8 JetStream: Mix file '/css/app.css' cannot be found when running npm run prod

I have a Laravel 8 application set up with Jetstream, Inertia Js, and VueJs 3. When I execute: npm run prod An error occurs: Exception Unable to find Mix file: /css/app.css. (View: /var/www/html/mysite/resources/views/app.blade.php) http://subdomain.mysi ...

Vue component retrieval on the client side

I am attempting to retrieve a component using Vue with cdn in order to dynamically re-render from a public project that contains a file named cash-sale.vue with the .vue extension. <script> export default { data(){ return { "rows&quo ...

Issue encountered while attempting to save the date to a json file

While working on my code to directly print the date from index.js into data.json, I encountered an error stating that data is not defined. This is what I have done so far: Ran npm init Installed jsonfile using npm i jsonfile index.js const json ...

Ensure the vertical dimension of the webpage is properly maintained

I am currently working with a client who has requested a website design with a specific height for the content section. The Inquiry: Is it possible to automatically create a new page for text that exceeds the maximum height of the content section on the ...

issue arises when trying to build vue3 with element-ui on node:16-buster-slim container

dockerfile: FROM node:16-buster-slim RUN apt-get update WORKDIR /app COPY package.json /home RUN npm install --prefix /home package.json { "name": "test", "version": "0.1.0", "private": false, ...

I am having trouble with my quiz function as it only checks the answer correctly for the first question. Does anyone have suggestions on how to make it work for

Currently, I'm tackling a quiz project that was assigned to me during my bootcamp. My focus right now is on the checkAnswer function, which evaluates the answer selected by the player. const startButton = document.querySelector(".start") as ...

The secret to mastering Selenium WebDriver: Waiting Implicitly

Is it possible to create an implicit wait in JavaScript WebDriver? Here is a Python example: browser.implicitly_wait(1) ...

What purpose does @ViewChild serve if we are unable to modify or interact with its properties from the Parent Component?

I have two main components - home and about. Within both of these, I am including a third component called hearts. Currently, I am manipulating the value of the 'age' property in the hearts component (initially set to '23') using @ViewC ...

word-wrap: break-word; repair or substitute

Is there a way to prevent line breaks before words that are going to break anyway when using word-wrap: break-word;? It seems unnecessary and unattractive. Any suggestions? For Example: Consider a div with word-wrap: break-word;, set at a width equal to ...

Guide for Uploading, presenting, and storing images in a database column with the help of jQuery scripting language

What is the best method for uploading, displaying, and saving an image in a database using jQuery JavaScript with API calls? I am working with four fields in my database: 1. File ID 2. Filename 3. Filesize 4. Filepath ...

"The changes made to the list are not being accurately displayed by Angular's ng

I am working on a directive that injects dynamic templates during ng-repeat. While I can successfully add items to the list, they do not appear in the view for some reason. It seems like I am missing a crucial piece to make it work correctly. You can find ...

Press the button to activate the function

<table class="calc" cellpadding=2> <td><input type="button" class="calc" id="screen" value="0" ></td> <td><input type="button" class="calc" id="screen" value="0" ></td> <tr> </ ...

Drop-down functionality in Bootstrap Form becomes unresponsive after screen width is decreased

I recently encountered a strange issue with my simple Bootstrap form. When I resize my browser width to mobile size or view it on a mobile device, the form stops functioning properly. Unfortunately, I am unable to provide any specific code examples at this ...

What is the best way to access a variable within an event handler function?

Is there a way to retrieve values from the for-loop within an event handler? Consider this JSON array var items = [ { "id": "#id1", "name": "text1" }, { "id": "#id2", "name": "text2" } ]; that is passed as a parameter to the function function setHand ...

JavaScript accordions failing to open

I've encountered an issue with my website that includes JS accordions. Strangely, they are not opening on the live site, but they function properly on Codepen. I checked the console in Chrome and found no error messages, however, when I looked at the ...

Saving the author of a message from one function and transferring it to another

I'm currently working on a Discord bot that manages tickets as applications. I've almost completed it, but I want the bot to log the closed ticket when the -close command is used. I've experimented with different approaches, such as using a ...

Error 404 in Angular HTTP Request

I'm encountering a 404 error while attempting to send a post request, along with a 'possibly unhandled rejection' error. Given my limited experience with Angular, any advice would be greatly appreciated. I've gone through the documentat ...