Creating a Vue.js component with dynamic data

Recently, I started working with Vue.js and have been experimenting with it for a few days. One of the challenges I'm facing is trying to dynamically add a new div element with text input every time the enter button is pressed. I would greatly appreciate your help in reviewing this code.

Script

window.onload = function () {
        Vue.component('todo-item', {
            props: ['todo'],
            template: '<div id="div{{todo.id}}">{{ todo.text }}</div>'
        });

        var app7 = new Vue({
           el: '#app-7',
           data() {
               return {
                   divList: [],
                   textInput:''
               }
           },
           methods: {
               addUser() {                        
                   return this.divList.push({
                       id: + new Date,
                       text: textInput
                   });
               }
           }
       });
}

HTML

<div id="app-7">
              <input v-model="textInput" v-on:keyup.enter="addUser" />
              <todo-item v-for="item in divList" v-bind:todo="item" v-bind:key="item.id"></todo-item>
          </div>

After checking the value of app7.textInput on the JavaScript console, I noticed that it's not binding properly...

Answer №1

Appreciate it Bert! I simply made that modification and cleared the cache

         functions: {
                        insertUser() {
                            this.userList.push({
                                userId: + new Date,
                                userText: this.enteredText
                            });
                        }
                    }

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

Which is more efficient: Implementing caching on the frontend or on the

Currently, I am using ajax to send requests to the backend server, where operations are performed and responses are received: function getData() { new Ajax().getResponse() .then(function (response) { // handle response }) .catch(functi ...

Personalized information boxes for particular data points within highcharts

When hovering over specific points, I want to display unique warnings or explanations in the tooltip. I have included custom text like 'WARNING' and 'WARNING 2' within the series data but am struggling to retrieve that data for each too ...

Safari is not properly handling element IDs when used in conjunction with React

I am currently in the process of building a straightforward single-page website utilizing React. At the top of the page, there is a navigation bar that contains links to various sections of the site: <li><a href="/#about">About u ...

What is the reason behind getElementsByClassName not functioning while getElementById is working perfectly?

The initial code snippet is not functioning correctly DN.onkeyup = DN.onkeypress = function(){ var div = document.getElementById("DN").value document.document.getElementsByClassName("options-parameters-input").style.fontSize = div; } #one{ heigh ...

Issue with React nodemailer: net.isIP() is not a valid function

I'm currently working on a contact page in React and facing difficulties with the email functionality. My attempt involves using nodemailer and here is the snippet of my code: var nodemailer = require('nodemailer'); var xoauth2=require(&ap ...

Proper method for incorporating loading and error messages with the help of useContext and react hooks

Currently, I have a context.js file that makes an ajax call and stores the data in an array to be shared across components. While adding some 'loading ...' text during the loading process using axios, I feel there might be a better way to handle ...

Tips for integrating TypeScript with Vue.js and Single File Components

After extensive searching online, I have struggled to find a straightforward and up-to-date example of setting up Vue.js with TypeScript. The typical tutorials out there either are outdated or rely on specific configurations that don't apply universal ...

Discovering the indices of undefined array elements in JavaScript without using a loop

Is there a way in JavaScript to retrieve the indexes of undefined array elements without using a loop? Possibly utilizing a combination of map, filter, and indexOf? I have a loop solution that I'm seeking an alternative for - something more concise, ...

Why is it necessary to create a new object in Node.js to establish a server?

After reviewing the information about socket.io, there is one aspect that I find confusing. I understand that to create a server, it can be done like this: var io = require ("socket.io")(); However, I am curious about why it necessitates creating a new ...

What is the importance of the :key attribute in vuejs v-for loop?

My VS Code keeps giving me an error message about needing a certain attribute in my Vue.js v-for directive: INCORRECT <p v-for='person in people'> {{person.name}} </p> CORRECT <p v-for='(person, index) in people' :key ...

Editing HTML using the retrieved jQuery html() content

I need to modify some HTML that is stored in a variable. For example: var testhtml = $('.agenda-rename').html(); console.log($('input',testhtml).attr('name')); I also tried the following: console.log($(testhtml).find(' ...

Struggling to retrieve the session value using JavaScript in a C# application

Currently, I am attempting to retrieve four values from the session. However, I am only able to fetch two of them, while the other two seem to be missing. As a beginner, I apologize if my question comes across as too simplistic. Within a tree view, I have ...

I am working with AngularJS and I am having trouble redirecting my pages from the main screen. I am implementing the ng-route module. Can you take a look at my code and provide feedback?

I have encountered an issue with my index.html code. I am unable to load login.html when clicking on the login button. <!doctype html> <html ng-app="instagram"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compitable" co ...

Creating a cascading select menu based on the selected value of another select menu

I am in the process of creating a menu that displays two lists for regions: one <select> for selecting the region and another <select> for choosing from available municipalities within that region. I have set up a <form> and I utilize Jav ...

Tips for saving data obtained from an ajax call

My jquery ajax function has a callback that creates an array from retrieved json data. Here's an example: success: function (response) { callback(response); }, The callback function, in this case createQuestionsArray(), populates ...

Assistance needed for jQuery functions running too early

Within my click function, I am setting certain flags and then calling two functions. However, I want these two functions to execute sequentially in order after the flags have been set. jQuery("#element").click(function(e){ var op = jQuery("#box" ...

How to break down JSON into individual elements using JavaScript

{ "name": "Sophia", "age": "Unknown", "heroes": ["Batman", "Superman", "Wonder Woman"], "sidekicks": [ { "name": "Robin" }, { "name": "Flash Gordon" }, { "name": "Bucky Barnes" } ...

Can you explain the distinction between the GenerateSW and InjectManifest choices within the vue ui pwd configuration?

Currently utilizing @vue/cli for building a vue project. I have initiated vue ui to access the vue UI and am in the process of customizing various available options. https://i.sstatic.net/h77AE.png Within Configuration -> PWA, I have come across the a ...

Disable default styling on <v-card-actions>

Currently utilizing Vuetify, here is a simple setup for a <v-card> component: <template> <v-card> <v-card-title>MyCard</v-card-title> <v-card-text></v-card-text> <v-card-actions> <v-btn ...

Exploring ways to extract HREF using Selenium in combination with Node JS

I am having trouble extracting the hrefs from my web element using .getAttribute("href"). It works fine when applied to a single variable, but not when looping through my array. const {Builder, By, Key, until} = require('selenium-webdriver'); (a ...