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

What is the solution to the error message that states a bind message provides 4 parameters, while a prepared statement "" necessitates 5?

Is there a way to fix the issue where the bind message provides 4 parameters but the prepared statement "" requires 5? I've tried solutions from others who faced similar problems without success. (I've included all classes for better error unders ...

The information in columnSummary is missing

Recently, I've been attempting to incorporate columnSummary into my table using Handsontable. Strangely enough, it appears that the function isn't being triggered. Even though the stretchH value is properly set, the table doesn't respond to ...

Error unfound: [CLIENT_MISSING_INTENTS]: The Client requires valid intents to function properly

I've gone through multiple tutorials, but I keep encountering an uncaught TypeError. Despite following the suggested solutions, the error persists. I even tried implementing the "intent" solution, but it's prompting a change in "const client = ne ...

having trouble transferring the password field in PHP to phpMyAdmin

My HTML form collects the user's first name, last name, username, and password. I am trying to upload this data to my local phpMyAdmin, but I'm facing an issue with storing the password in the database. Below is my HTML code: <input type="te ...

A guide on updating data dynamically in Vue.js

I am facing an issue with Vue JS in my frontend development. Here is the data for my component - data: () => ({ email: "", showError : false }), Below is the corresponding HTML code - <div v-show='showError' c ...

Is there a way to confirm whether the current date and time, based on a specific timezone and hour, is before or equal to a particular date?

I am working on a project that involves a timezone map with publishing hour in the local zone and news articles that need to be scheduled using a date picker. This particular article is set up as follows: { timeZoneId: 'Europe/Paris, releaseHour: 9 ...

Managing data overload in Node.js can lead to Promise Rejection Warnings

I'm currently developing a feature where scanning a barcode adds the product information to a table. Once the data is in the table, there is a button to save it. Each row requires generating a unique stamp and inserting into tables named bo, bo2, and ...

Tips on preventing the opening of a new browser tab by using Ctrl + click

Hey there, I've got a list of products that can be selected using the Ctrl key. $(parentSelector).on("click", function (evnt) { evnt.stopImmediatePropagation(); var item = $(evnt.delegateTarget) ...

Struggling to get my JavaScript function for calculating one rep max to work, need some help figuring out the issue

I have been working on a one rep max calculator using the Epley Formula. However, when I try to call the function, it returns as undefined. I have utilized the parameters weight and reps, both of which are parsed as integers, believing that they would be e ...

How can you leverage Symfony to iterate through a JSON array efficiently?

After selecting a user, I am attempting to display a list of contracts. To achieve this, I have written the following query: /** * @param $firstname * @param $lastname * @return mixed * @throws DBALException */ public function getListPerUser($firs ...

Can a webpage be sent to a particular Chromecast device without using the extension through programming?

My organization has strategically placed multiple Chromecasts across our facility, each dedicated to displaying a different webpage based on its location. Within my database, I maintain a record of the Chromecast names and their corresponding URLs. These d ...

I am looking to update the count value in a Vue app by utilizing v-model within the Vuex store

I am experiencing an issue where this code does not generate an error, but when I change the count it does not reflect on the screen. Can someone please assist me in resolving this problem? import Vue from 'vue' import Vuex from 'vuex&ap ...

Ways to retrieve every element inside a specific div container

Is there a way to select all elements inside a div except for specific ones? For example, consider the following structure: <div id="abc"> <div class="def"> sagar patil</div> <div class="pqr"> patil</div& ...

Setting default parameters for TypeScript generics

Let's say I define a function like this: const myFunc = <T, > (data: T) => { return data?.map((d) => ({name: d.name}) } The TypeScript compiler throws an error saying: Property 'name' does not exist on type 'T', whic ...

What is the correct way to pass the res object into the callback function of a jest mock function?

Currently, I am working on developing a web server using Node.js and am in the process of ensuring comprehensive test coverage with Jest. One specific function, logout, requires testing within the if statement where it checks for errors. // app.js functio ...

Error: Unable to access 'price' property of undefined - Next.js version 14.0.1

I'm encountering an issue with Next.js where my code is not working as expected. Interestingly, the same code works perfectly fine in other templates. let subTotal = 0 if (selectedProducts?.length) { for (let id of selectedProducts) { ...

Updating Angular JS views in real-time using database changes

I am currently in the process of building a social networking application using AngularJS. I have come across an issue regarding data binding. In my app, there is a timeline div where all the recent posts are displayed, along with a status updater at the t ...

Assigning a value to an input field using jQuery

I'm facing an issue while trying to set the value for an input using jQuery. Essentially, when you click on a link, it redirects you to a different page with a form, and I am attempting to set the value of one of the inputs in that form. Unfortunately ...

Bidirectional data binding in AngularJS for <option> elements generated from an AJAX request

I have built a Controller called WebsiteController with the following functionality: JApp.controller('WebsiteController', function($scope, $resource) { var UsersService = $resource('/auth/users', {}); $scope.adding = false; ...

Transform jQuery scroll script into vanilla JavaScript

While I am quite familiar with jQuery, I find myself struggling when it comes to using pure JavaScript. Could anyone provide guidance on how I can convert my jQuery code into vanilla JavaScript? Your help is greatly appreciated! Below is the code that I ...