The Vue v-for directive encountered an unrecognized property during rendering

Trying to grasp the concept of v-for in Vue JS, especially since I am a newcomer to this framework.

Since I am utilizing Django, custom delimiters are necessary. I have a script example that appends a list of objects to a data property:

var app = new Vue({
    delimiters: ['[[', ']]'],
    el: '#app',
    data: {
        loading: true,
        datasetFilesArray: null
    },
    methods: {
        datasetFiles: function () {
            axios.get('api/list_all_data')
                .then(response => {
                    this.loading = false;

                    this.datasetFilesArray = response.data;
                })
                .catch(error => {
                    console.log(error)
                });
        }
    },
    beforeMount() {
        this.datasetFiles()
    }
});

At first, datasetFilesArray is null, but once the response arrives, it gets replaced by an object.

However, when attempting to use this in HTML tags like so:

...
<tr v-for="content in datasetFilesArray">
    <th class="align-middle">
        <a href="">[[content.file_name]]</a>
    </th>
    <th class="align-middle">[[content.date]]</th>
</tr>
...

An error pops up stating that

Property or method "content" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
Everything works smoothly though when adding content to data as shown below:

...
data: {
    loading: true,
    datasetFilesArray: null,
    content: null
},
...

In contrast, the example provided at https://v2.vuejs.org/v2/guide/list.html#v-for-with-an-Object, does not initialize the value keyword and yet it seems to work fine.

Am I overlooking something?

Update

I considered the possibility that the property might be taken from the meta tag such as

<meta http-equiv="X-UA-Compatible" content="ie=edge">
, so I switched it from content to datasetItems but encountered the same error.

Update 2

Here's an example of my page: https://codepen.io/akshaybabloo/pen/ExxexxE

If you check the developer tools, you'll notice the error I mentioned earlier.

Answer №1

UPDATE I have some concerns about this:

<tr v-for="content in datasetFilesArray">
    [[content]]

You should not place text directly within a <tr> element, it should be enclosed in a <td> or a <th> instead. Otherwise, the content will get pushed out of the <tr> (refer to my note on HTML tables below).

Before Vue compiles the template, the DOM structure looks like this:

[[content]]
<tr v-for="content in datasetFilesArray">

Evidently, content is being used beyond its scope and is treated as a property of the component instance due to how the render function is wrapped in a with statement (which explains this behavior). Since content is undefined on the component, Vue raises a warning. When you define content in the component's data property, the warning disappears but only complicates matters.

Consider using this approach instead:

<tr v-for="content in datasetFilesArray">
    <th>[[content]]</th>

Additionally, I recommend reading Why You Should Avoid Vue.js DOM Templates for more insights.


The error cause is unclear based on the information provided. Can you share a fiddle?

The error suggests that content is not properly declared within the template's scope. As it's declared by v-for, any usage of content within <tr> should be valid. Any other use of

content</code in the template could lead to this error.</p>

<p>Check your JavaScript code to ensure <code>this.content
is not accessed anywhere, particularly in methods or computed properties used within the template.

HTML tables can be tricky; at times, browsers might auto-close elements if the table markup is incorrect. Try changing <table>, <tr>, <th>, and <td> to <div>. It would be helpful to provide your complete HTML for further debugging.

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

Whenever I try to retrieve data from MongoDB using Node.js, I consistently encounter a timeout error

Currently, I am in the process of developing a website using React.js for the front end, Node.js for the back end, and MongoDB as the database. Dummy data has been inserted into the database which can be viewed . The database has been created in Atlas, the ...

How do I delete an attached file in an input document? (Firefox)

Is there a way to smoothly remove an attachment selected in the <input type="file"> element? In Firefox, removing an already selected attachment can be tricky. Simply deleting the name or trying to click open may not work. An additional solution mi ...

Utilizing Jquery's .GET method to retrieve and handle JSON data

In the jQuery snippet below, I am trying to fetch product data from . However, I am facing difficulty in iterating through the loop to access all 30 products along with their details. $.get("https://dummyjson.com/products/1") .done(function ...

I am interested in incorporating `connect-history-api-fallback` into my project in Vue.js, but I am unsure about the implementation

After refreshing the page in Vue.js, I encounter an Nginx error. I am currently using 'connect-history-api-fallback', but I'm uncertain about how to implement it in Vue.js. I noticed its usage in app.js with middleware server; how can we use ...

Utilize the `npm ls somepackage` command to adhere to version range specifications

I need to utilize npm ls to pinpoint the source of security warnings. Reference to the documentation states that: Positional arguments consist of name@version-range identifiers, which will restrict the outcomes to only the paths leading to the specified ...

Angular 8 utilizes JavaScript for its programming language

Looking for a solution in JavaScript - check out: codepen.io/skovtun/pen/VwLvXPB Struggling to find an equivalent for Angular 8+. I want the center block to maintain a fixed width of 1200px, and automatically compress when the left, right, or both sideb ...

Struggling to grasp the concept within this particular Array.map callback

Within my React component, I am exploring the concept of the this keyword and its context with the following code snippet. While this example may seem simple, it is part of my efforts to enhance my comprehension. const NAVBAR_ITEM_TITLES = ["Home" ...

Preparing my JSON data for visualization on a chart

I have successfully retrieved data using this API, but now I need to transform it into a chart within my react project. As a newcomer to JS and React, I am struggling to create a chart with the JSON data. My objective is to display prices by bedrooms over ...

Encountering an unexpected response while watching Vue in Android Chrome

In my project, I have a component called tagger that filters an array of tags. A simplified version of the code can be found here. This component revolves around an input field: <input v-if="showInput" type="text" class="tag_input__input" :id= ...

Exploring the Vanilla JavaScript alternative to the jQuery.each() function

$.fn.slideUpTransition = function() { return this.each(function() { var $el = $(this); $el.css("max-height", "0"); $el.addClass("height-transition-hidden"); }); }; When utiliz ...

Creating dynamic routes for every page fetched from the API in Next.js

Hello everyone, Recently, my journey with NodeJS just commenced and I have been exploring API routes in NextJS as it provides an easy setup and clear visibility of the processes. While I have a grasp on creating basic get requests, I am now intrigued by s ...

Troubleshooting: JavaScript Object isn't appending to array

(Just so you know, I really appreciate your help as I navigate through teaching myself). I'm currently working on recreating an array that was previously parsed from session storage. var entries = JSON.parse(sessionStorage.getItem('entries&apo ...

Switching a component in Mui App transforms the entire aesthetic

I'm currently working on a project using Mui and the Material Kit theme. While I initially tried to customize the default components provided by Material Kit using custom CSS, I found that I was unable to override the styles as expected. Consequently, ...

Angular styling and form error issue

Hey there! I'm new to Angular and facing a major issue along with a minor styling problem. Let's start with the big one: <mat-form-field appearance="fill"> <mat-label>Password</mat-label> <input matInput ...

What could be causing the axios response to come back empty in this scenario?

I keep getting this error on the console: "IntegrationError: stripe.redirectToCheckout: You must provide one of lineItems, items, or sessionId." I suspect that sessionId is empty because when I log response.data, it returns an "empty strin ...

Is there a way for me to generate a preview thumbnail for my video?

Looking to add a preview effect to video thumbnails when users hover over them, displaying a series of frames from the video. Are there any jQuery plugins or tutorials available for creating this effect? ...

Encountering SCRIPT1014 and SCRIPT1002 errors within an Angular4 application when using Internet Explorer 11

My Angular 4 application runs perfectly in various browsers. However, when trying to launch it in Internet Explorer version 11, I encounter the following two errors: SCRIPT1014: Invalid character addScript.js (9,1) SCRIPT1002: Syntax error main.bundle.js ...

Express.js post method malfunctioning for BMI calculation

Currently, I am working on a BMI calculator application in JavaScript as part of my practice. The app is supposed to take two inputs - weight and height, calculate the BMI, and display the result on the web page. However, after inputting the data and submi ...

A useful Javascript function to wrap a string in <mark> tags within an HTML document

I have a paragraph that I can edit. I need to highlight certain words in this paragraph based on the JSON response I get from another page. Here's an example of the response: HTML: <p id="area" contenteditable> </p> <button class="bt ...

Vue enables components to be used in any part of the application, not limiting them to

Currently, I am initializing my Vue instance in the following manner: import ListClubsComponent from "./components/clubs/list-clubs.vue"; new Vue({ el: "#app", components: { "list-clubs": ListClubsComponent } }); It seems to be functi ...