How come it's so difficult for me to find a simple demonstration of v-for in action in Vue JS?

After searching for a simple "hello world" example of using v-for in Vue.js, I have spent an hour looking at various posts, like the one on Stack Overflow, but still no luck.

This is my HTML:

<ul>
    <li v-for="item in history">
        {{ item }}
    </li>
</ul>

This is my JavaScript:

new Vue({
    el: '#app',
    data: {
        history: [
            'red','green','blue'
        ],
    },
});

This is the output I am getting: {{ item }}

https://i.sstatic.net/c0cqC.png

I would appreciate any help in figuring out what I am doing wrong and why this basic example is not working. I have tried different approaches with arrays, objects, and key attributes without success.

Refer to the documentation here: https://v2.vuejs.org/v2/guide/list.html

EDIT: I apologize for the multiple title changes I had to make before posting this question.

EDIT 2: Just to clarify, I have the app defined with the entire body of HTML enclosed within <div id="app">.

EDIT 3: Issue resolved - it seems I had inadvertently closed a div tag prematurely, commenting it out fixed the code. Thank you for the responses.

Answer №1

It seems like the id app is not defined in the HTML section. Here is a revised code snippet that should work.

new Vue({
  el: '#app',
  data: {
    history: [
      'red', 'green', 'blue'
    ],
  },
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<ul id='app'>
  <li v-for="item in history">
    {{ item }}
  </li>
</ul>

Answer №2

Make sure to include the id "#app" in your code snippet

<div id="app">
    <span v-for="element in list">
        {{ element }}
    </span>
</div>

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

Is there a shared instance for regular expressions created using expression literals?

In the book "Javascript: The Good Parts" by Crockford, there is a code snippet that highlights how RegExp objects created using regular expression literals share a single instance: function create_matcher() { return /a/gi; } var x = create_matcher(); ...

Basic Search tool, displaying a <div>

Hey there, I've been searching for a solution for a while now and haven't found one yet. So here's my question: I created a simple website to display random recipes for those times when you're not sure what to make for dinner. I also w ...

What is the reason that modifying a textarea causes the AJAX loading of content to be interrupted?

I am currently developing a feature that allows users to quote comments on my website. When a user wants to reply to a specific comment, they can simply click on the "quote" button next to that comment. This action triggers a script that adds the quoted co ...

How can I retrieve an updated object array within an extended class in JavaScript?

Hey everyone, I am new to working with ES6 classes. Currently, I am trying to inherit an initialized object (this._obj) with updated data in the class B, but I am encountering an issue where I am getting the length of the initialized object instead of the ...

The function you are trying to call is not valid... the specified type does not have any call signatures [ts 2349

Having some trouble using functions from Observable Plot example with a marimekko chart in my TypeScript project. I encountered an error on this particular line: setXz(I.map((i) => sum.get(X[i]))) The code snippet causing the issue is as follows: fu ...

``There seems to be an issue with implementing the SlideDown feature in JavaScript

I am having an issue with a code where the expected behavior is to slide down a div when a person hovers over text, but it's not working. Can someone please review and identify the cause of this problem? <script type="text/javascript" src="/js/jqu ...

Utilizing a JSONSerializer to format a Java String Array

I am faced with a challenge involving a Java array consisting of 5 strings. My goal is to display this data using Flot Charts, which requires transferring it from a Java file to an HTML file with accompanying JavaScript code. Despite various attempts, I ha ...

Sort firebase information by chronological order based on timestamp

I'm currently working on sorting track IDs from firebase based on their timestamp (createdAt). The function is functioning correctly, but the ordering doesn't seem to work as expected. I'm not sure where the issue lies. Any assistance or sug ...

Implementing the Google Maps API into a React application to generate a customized route between two specified points

I'm currently developing a React application that is designed to display the distance between two points on a map. Although I successfully implemented this feature using JavaScript and HTML, I am facing challenges in converting it to React as I am re ...

Success function in Classic ASP with Ajax Form isn't functioning properly, but the complete function is working fine

When using Ajax and JS/Jquery, I am attempting to send a basic Contact form to a Classic ASP (aspemail) without reloading the page. <form id="form-submit" action="ASPEmail.asp" method="post"> Name<br> <input id="name" type="text"&g ...

Displaying infowindow pop-ups on random markers on Google Maps every 3 seconds

Here lies the challenge. I am tasked with creating a Google map that displays multiple markers. Each marker must have a unique info window with distinct content. Upon opening the website, an info window randomly appears on one of the markers after 3 sec ...

What is the best way to display table rows for a specified date range?

I am working with a table and need to display only the rows that fall between two specific dates. <table id ="Table"> <thead> <tr> <th>Date</th> <th>Name</th> <th>Desc</th> </tr> </thead> ...

Error encountered: Circular reference issue was encountered when attempting to retrieve navigator.plugins with the use of Selenium and Python

I'm attempting to access the value of navigator.plugins from a Selenium-driven ChromeDriver initiated google-chrome Browsing Context. Using google-chrome-devtools, I am able to retrieve navigator.userAgent and navigator.plugins as shown below: https ...

Is it possible to assign a class to the initial word within a designated class?

How can I customize the first and second word of a specific class in my code? This is an example of my current code: <h2 class="content-heading">Latest News</h2> I would like to achieve something similar to this: <h2 class="content-headi ...

Show method created by function, substituting the former element on the display

showButtons(1) will show radio buttons for frame number 1, showButtons(400) will display radio buttons for frame number 400. The current code shows all radio buttons for every frame up to 400 HOWEVER, I am aiming for a single set of radio buttons to start ...

Extracting and passing a JSON object to a Spring controller

I have a file upload feature on my jsp page that specifically accepts json format files. I want to retrieve the uploaded json file and pass it to a Spring controller for further processing. This is how my javascript code appears: var file = this.files[0] ...

Node.js can be utilized to make multiple API requests simultaneously

I am facing an issue while trying to make multiple external API calls within a for loop. Only one iteration from the for loop is sending back a response. It seems that handling multi-API requests this way is not ideal. Can you suggest a better approach fo ...

Jesting around with mocking console.error leads to test failures

The Issue: Currently, I am working on testing React components using Jest and Enzyme. In order to check for properties in development, I have incorporated the prop-types module. The prop-types module relies on console.error to alert when mandatory props a ...

Issue with VueJs 3 checkbox binding to an array of objects is not functioning as expected

I am struggling to figure out why my v-model is not functioning properly. I have an object called 'service' with a property 'actions' of type IAction[]. Additionally, I have declared an array called actions which also contains IAction o ...

What is the best way to position the list element to align with the top of a div container?

To see a live example, visit this link. My goal is to create a line that separates two li elements within a nested ul. However, the line ends up taking the width of the container ul instead of the div containing the entire structure. In the provided examp ...