Vue caution: The reference to property or method "list" during render is not defined on the instance. Ensure that this property is reactive and properly declared

I'm currently exploring the characters from the Rick & Morty series app using vue.js, and I am still learning how to use vue.js.

However, I encountered the following error and would appreciate help in resolving it:

Error1: [Vue warn]: Property or method "list" is not defined on the instance but referenced during render. Please ensure that this property is reactive, either in the data option or for class-based components by initializing the property.

// App.vue file //

<template>
  <div id="app">
    <Nav />
    <CharactersList />
  </div>
</template>

<script>
import Nav from './components/Nav.vue'
import CharactersList from './components/CharactersList'
export default {
  name: 'App',
  components: {
    Nav,
    CharactersList
  }
}
</script>

// CharactersList.vue file //

<template>
    <div>
        <h1>Rick and Morty characters</h1>
        <table border="1px">
            <tr>
                <td>Character ID</td>
                <td>Name</td>
                <td>Species</td>
                <td>Add to fav</td>
            </tr>
            <tr v-for="item in list" v-bind:key="item.id">
                <td>{{item.id}}</td>
                <td>{{item.name}}}}</td>
                <td>{{item.species}}</td>
                <button>Add to fav</button>
            </tr>
        </table>
    </div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
Vue.use(VueAxios, axios)
export default {
  name: 'CharactersList',
  data: function () {
    return {
      list: undefined
    }
  },
  mounted () {
    Vue.axios.get('https://rickandmortyapi.com/api/character/')
      .then((resp) => {
        debugger
        this.list = resp.data.results
      })
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

Answer №1

First and foremost, there is no need to import Vue and VueAxios in that context. Furthermore, it is essential to update the value of your list variable from undefined to []

The code for your CharactersList component has been modified. You can simply copy and paste the following codes to achieve the desired functionality:

CharactersList.vue

<template>
    <div>
        <h1>Rick and Morty characters</h1>
        <table border="1px">
            <tr>
                <td>Character ID</td>
                <td>Name</td>
                <td>Species</td>
                <td>Add to fav</td>
            </tr>
            <tr v-for="item in list" v-bind:key="item.id">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.species}}</td>
                <button>Add to fav</button>
            </tr>
        </table>
    </div>
</template>
<script>
import axios from 'axios'
export default {
  name: 'CharactersList',
  data: function () {
    return {
      list: []
    }
  },
  mounted () {
    axios.get('https://rickandmortyapi.com/api/character/')
      .then((resp) => {
        this.list = resp.data.results
      })
  }
}
</script>

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

Troubleshooting not locating view files in ExpressJS and implementing client-side JavaScript and CSS deployment in ExpressJS

My JavaScript file is located in the same directory as my HTML file, and I am trying to render it. I'm unsure of what I may be missing. How difficult could it possibly be? var express = require('express'); var app = express(); app.engine( ...

Switch between the table data elements in an .hta document

The response provided by Dr.Molle in a previous post here was accurate, but it only functioned with <div>. I am required to utilize <table>. Though I found a script that works flawlessly outside of my VBScript, it does not work when embedded in ...

What is the best way to show instructions immediately upon receipt of a response?

I'm currently working on developing a website similar to ChatGpt using the OpenAI API for GPT. However, there is a delay in generating responses with GPT taking a few seconds. As a result, my code only displays the instruction once the response from G ...

Creating an AI adversary for a simple Tic Tac Toe game board: a step-by-step guide

Being new to programming, I recently completed a basic Tic Tac Toe gameboard successfully. However, as I progress to the next phase of my assignment which involves implementing an AI opponent, I encountered several challenges. As a novice in programming, ...

Error: Request for resolution of all parameters for SignupComponent failed: ([object Object], ?). Occurred at the syntaxError in compiler.js:2175

Could someone assist me in resolving this issue? signup.component.html <main role="main" class="container> <h1 class="mt-5">&nbsp;</h1> <h5 class="mt-5 ">Create Account</h5> <br/> <div class="loa ...

Exploring the Use of 7BitEncodedInt in JavaScript

Currently, I am trying to read a binary file using JavaScript. It appears that this file may have been written in C#, which handles strings differently from how it's done in the source mentioned at https://learn.microsoft.com/en-us/dotnet/api/system. ...

Issue: Debug Failure. Invalid expression: import= for internal module references should have been addressed in a previous transformer

While working on my Nest build script, I encountered the following error message: Error Debug Failure. False expression: import= for internal module references should be handled in an earlier transformer. I am having trouble comprehending what this erro ...

Is it possible to use require() to read a .json file from a dependent library?

Is it possible to access a .json file within one of my dependent libraries? I'm hesitant to use fs to read ./node_modules/somelib/properties.json because the library could have been installed globally. Is there a way to achieve this using require in ...

Peer dependency conflict detected: [email protected]

Encountering a conflicting peer dependency error: [email protected] while attempting to build/deploy my Vue CLI application using Heroku: npm ERR! Could not resolve dependency: npm ERR! peer eslint-plugin-vue@"^7.0.0" from @vue ...

Is the value of the object in the array already present in another array of objects?

Plunker - http://plnkr.co/edit/jXdwOQR2YLnIWv8j02Yp In my angular project, I am working on a view that displays a list of users in the main container (array-A) and a sidebar with selected users (array-B). The first array (A) contains all users: [{ $$has ...

Strategies for including JavaScript variables in AJAX data

I have a basic webpage displaying employee names that can be dragged around using Jquery UI draggable. I am able to capture the "top" and "left" position of the dragged item and store it in a JavaScript variable. My next goal is to pass these two variable ...

Optimizing HTML and Script loading sequences for efficient execution

I have a query regarding the loading order of scripts in web browsers. I am interested in knowing the most efficient way to redirect users to a mobile website on the client side. For example, if I place a mobile detection script within the <head> se ...

Fetching the model or collection

Having recently transitioned from ExtJS to Backbone, I am looking to populate a Backbone collection with data. In ExtJS, I would typically use the .load() method to accomplish this. However, in Backbone's documentation, I notice that there are primari ...

Unable to transfer array from backend to vuex store

Issue: Encountered an error in the created hook (Promise/async) - "TypeError: state.push is not a function" Function used in the page created: async function () { this.$store.commit('TicketSystem/ADD_BOARDS', (await this.$axios.get('htt ...

JavaScript never forgets to validate the user input

Forgive me for my lack of experience, but I am new to this and seeking guidance. I am struggling to find a straightforward example on how to validate HTML input using JavaScript. Currently, I am working on a search function and need help in implementing ...

Guide on transforming the best.pt model of YOLOv8s into JavaScript

After successfully training a custom dataset on YOLOv8s model using Google Colab, I now have the best.pt file that I want to integrate into a web app via JavaScript. I've come across mentions of TensorFlow.js as a potential solution, but I'm stil ...

Getting an undefined error value in the ionic overlay side menu - what could be causing this issue?

My current challenge involves displaying the overlay side menu. I have written code to achieve this, adding a menu icon in the header that opens the overlay side menu when clicked, and closes it when clicked outside. However, I encountered an issue where ...

Using JQuery to cycle a class with a timer

My list has the following structure <div id="slider"> <ul> <li class='active'> a </li> <li> b </li> <li> c </li> <li> d </li> <li> e </li> </u ...

What is the best method for distributing an Angular service from a library created using ng generate library?

I'm currently facing a challenge in sharing a service from the npm package that I created using ng g library with my Angular hosting application. While I have experience in linking components and directives, I'm a bit lost when it comes to servic ...

Differences Between Android and JavaScript: Ensuring Library Validity

Validation in JS is provided by the validator library which can be found at https://www.npmjs.com/package/validator Is there an equivalent library for validation in Android? If so, what is the name of Android's library? ...