Is there a way to reset the input text in VueJS once a button has been clicked?

Is there a way to make the text in the input box clear once the enter button is pressed and the addTask function is executed to add the task to the list? I attempted to use document.getElementById("inp").innerHTML = "" but it didn't work. Any suggestions on how to achieve this?

HTML:

<div id="todo">
    <h1>To-Do List</h1>
    <section>
        <input type="input" placeholder="what do you need to do?" v-model="newTask" v-on:keyup.enter="addTask" id="inp">
    </section>

    <ul>
        <li v-for="task in todoList">
            <label>{{ task }}</label>
            <button type="button" v-on:click="removeTask(task)">X</button>
        </li>
    </ul>

</div>

VueJS:

var todo = new Vue({
    el: 'div#todo',
    data: {
        newTask:'',
        todoList: []
    },
    methods: {
        addTask: function() {
            var task = this.newTask
            this.todoList.push(task)
        },
        removeTask: function(task) {
            var index = this.todoList.indexOf(task)
            this.todoList.splice(index, 1)
        }

    }
})

Answer №1

erase your design:

createTask: function() {
                var task = this.newTask
                this.todoList.push(task)

                this.newTask = ''
            }

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

Creating an Engaging Discord Bot: A Step-by-Step Guide

I'm in the process of developing a Discord bot and I'm interested in adding a unique feature to it. I want to create an interactive system where users can request help through DM with the bot, and the support team can respond through the bot as w ...

Optimal method for file uploading with Node.js

How can I effectively manage file uploads in node js? I would like users to be able to upload profile images with the following specifications: -Validated size of at least 200 * 200 -Accepted file formats are png, jpg, jpeg, or gif -Additional functi ...

The Geocoder.geocode() method returns XML instead of JSON when invalid credentials are provided

Currently in the process of developing a program that converts addresses from a database to their corresponding lat/long coordinates using the HERE Geocoding API. In order for multiple users to utilize this program, they must manually input their app_id an ...

How can I generate a dummy JSON response using Backbone Fetch?

Exploring Backbone and looking for a way to simulate the response of a .fetch() call within a model without using a testing library or connecting to an external service. If the setting in the model is this.options.mock === true, I'd like to use an in ...

Managing Data Types in AJAX Requests

Can you help me figure out why my AJAX call is not reaching success after hours of troubleshooting? It seems like the issue lies in the dataType that the AJAX call is expecting or receiving (JavaScript vs JSON). Unfortunately, I'm not sure how to addr ...

Exploring Angular 2 Routing across multiple components

I am facing a situation where I have an app component with defined routes and a <router-outlet></router-outlet> set. Additionally, I also have a menu component where I want to set the [routerLink] using the same routes as the app component. How ...

"Passing multiple arguments using *args is considered as a single

I have a function that I want to call multiple times with varying numbers of arguments. Here's an example: def iterator(iterations, function, *args): #called as: iterator(5, my_function, arg1, arg2, arg3) The number of arguments passed to the func ...

JavaScript and CSS animations offer dynamic and engaging ways to bring

I'm working on a div section and I want it to come down and rotate when a button is clicked. However, after moving to the bottom, it doesn't rotate as expected but instead returns to its initial position along the Y axis. How can I fix this issue ...

Pressing the reset button on a basic calculator

I am experiencing an issue with my calculator. It works fine initially, but after using the reset button, it stops functioning properly. Currently, I only have the multiplication set up as I debug this problem. I am new to JavaScript and would appreciate a ...

What is the best way to retrieve the results of an indexedDb request beyond the limitations of its callback function?

I am working on a form that has an input box which I want to auto-complete with values from an IndexedDb objectStore. Currently, it is functioning with two overlapping input boxes, using a simple array. However, I am looking to make it work with the values ...

Passing an event from Electron's IPC renderer to Vuex

Greetings, fellow developers! I'm currently working on an app that involves multiple windows. My App is built using Vue + Electron technology stack. One of the key features I am trying to implement is triggering actions in Electron to open a popup, fo ...

Setting a value for the identifier just one time

I've been grappling with an issue that's been on my mind for some time now. There are 14 divs on my webpage, and I need each one to be given a random ID (ranging from 1 to 14) every time the page loads. These divs all share the class ".image-box ...

Adjust jqGrid dimensions automatically as browser window is resized?

Does anyone know of a method to adjust the size of a jqGrid when the browser window is resized? I attempted the approach mentioned here, but unfortunately, it does not function correctly in IE7. ...

The jQuery message validator is currently experiencing some issues with its functionality

I am working on implementing a basic login system using jQuery and it appears to be functioning correctly, but I keep getting an error message in my jQuery code here: alert('Error in system');. What's puzzling is that when I use alert(answe ...

What is the proper way to parse an array of JSON objects?

Here is the data I need help with: var information = [ { "_id": "5e458e2ccf9b1326f11b5079", "xxTitle": "testtttttttttttt", "hhhhhhhhhh": "sssssssss", "xxzzzzzz": null, "oooooooooooooo": "ssssss", "xxDescription": "sssssss", "xxDetails": "ssssssss", "llll. ...

How can I delay the ng-show element until the ng-hide CSS transition has finished?

Looking for a simple solution to my implementation issues. I'm faced with the following DOM setup: <h1 class="fade" ng-repeat="child in parent.children" ng-show="parent.activeChild == child">@{{ child.title }}</h1> How can I smoothly fad ...

Boosting Website Loading Time with Puppeteer: A Guide

Currently, I am using Puppeteer for automating tasks and it is working well. However, I have noticed that when loading the website, it takes longer than my usual websites. I attempted to use caching with the following code: const puppeteer = require(' ...

jQuerry's on method fails to respond to newly added elements through the clone() function

I always thought that jquery's on() function would handle events for dynamically added elements in the DOM, such as those added via ajax or cloning. However, I'm finding that it only works for elements already attached to the dom at page load. Cl ...

Trouble encountered in nuxt/auth

When it comes to authentication, I utilize nuxt-auth. After a successful login, my intention is to redirect to the main page using this.$router.push('/'). However, upon doing so, I am encountering a blank page with the following message: 2021 ...

The Tauri JS API dialog and notification components are failing to function, resulting in a null return value

Currently, I am getting acquainted with the tauri framework by working on a small desktop application. While testing various tauri JS API modules, most of them have been functioning as expected except for the dialog and notification modules. Whenever I tes ...