Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
How do I make it so that I can edit my vue to do list to add items?

Ok, so, I am new to Vue and I am trying to make a simple to do list. I have managed to display it and stuff but I am having trouble with the code to add items to the list. When I click the button to add the task, it adds a bullet point but it doesn’t show the text given. For example, in the input box, I will type the name of a task but when I click the button, what I wrote doesn’t show up, just the bullet point.

I have tried putting the newTask part in other places but the same problem happens. I know this is probably a pretty silly question and the solution is probably pretty obvious but please help as fast as you can, I need to do this for school.

Here is my HTML:

<body>
  <div id="app">
    <!-- Vue App HTML Code -->
    <h1>To Do List</h1>
    <div id="app">
  <ul>
    <li v-for="x in tasks">
      {{ x.text }}
    </li>
  </ul>
</div>
    <div id="newTask">
      <input type="text" value="taskName" placeholder="Task Name" v-model="newTask"></input>
      <button v-on:click="tasks.push(newTask)">Add Task</button>
    </div>
</body>

And my JavaScript/ Vue:

myObject = new Vue({
    el: '#app',
    data: {
        tasks: [
            { text: '1' },
            { text: '2' },
            { text: '3' },
        ],
        newTask: ''
    },
})

I would really appreciate any other Vue tips (relevant or not) because it is my first week learning it and anything would be really useful.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can achieve this by pushing the newTask in the existing tasks array.

Working Demo :

var vm = new Vue({
  el: '#app',
  data: {
    tasks: [
      { text: '1' },
      { text: '2' },
      { text: '3' },
    ],
    newTask: ''
  },
  methods: {
    addTask() {
        this.tasks.push({ text: this.newTask })
      this.newTask = '';
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <h1>To Do List</h1>
  <ul>
    <li v-for="x in tasks">
      {{ x.text }}
    </li>
  </ul>
  <input type="text" placeholder="Task Name" v-model="newTask"/>
  <button v-on:click="addTask">Add Task</button>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda