Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda