During the rendering process, the property "quote" was accessed, however, it is not defined on the current instance. (Vue.js)

Every time I try to retrieve data from the kanye API, I encounter this error message:

Property "quote" was accessed during render but is not defined on instance.

Below is the code snippet that triggered the error:

<template>
  <div>
    <i>{{quote}}</i>
    <p>Kanye West</p>
    
  </div>
</template>

<script>
import axios from 'axios'
import { ref } from 'vue'
export default {

    setup() {

        const quote = ref('')

        const getQuote = async () => {
            const response = await axios.get('https://api.kanye.rest/')
            quote.value = response.data.quote
        }
        getQuote()

`

Answer №1

Don't forget to include the return statement for the quote in your setup function.

Check out the Live Demo below:

console.clear();

const { ref, onMounted } = Vue;

let options = {
  setup: function () {
    let quote = ref('');

    onMounted(function () {
      // This is just a demo using mock api response. You can replace it with actual API call.
      quote.value = 'Today\'s inspirational quote';
    });

    return {
      quote
    };
  }
};

Vue.createApp(options).mount('#app');
<script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="243316061c2b351b051b05283b3d39361c1316">[email protected]</a>/dist/vue.global.js"></script>
<div id="app">
  {{ quote }}
</div>

Answer №2

Simply retrieve the quote.

<template>
  <i>"{{ quote }}"</i>
  <p>Kanye West</p>
</template>

<script>
import axios from "axios";
import { ref } from "vue";
export default {
  setup() {
    const quote = ref("");

    const getQuote = async () => {
      const response = await axios.get("https://api.kanye.rest/");
      quote.value = response.data.quote;
    };

    getQuote();

    return {
      quote
    }
  },
};
</script>

Answer №3

Here is an alternative option:

{{quote.quote}}

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

Issue with Sliding Transition in React Material UI Drawer Component

I developed a custom drawer component for my React application const CustomSidebar = () => { return ( <Drawer open={drawerOpen} onClose={() => setDrawerOpen(false)} > <Box> <Navigator / ...

Prevent form submission once all tasks have been finalized

Hey there, I've been racking my brain for hours trying to solve this issue... I'm looking to disable my form after it's been submitted to prevent multiple submissions. However, every method I try seems to disable the button but also interfe ...

The issue with session storage persisting even after closing the iframe

Encountering a persistent issue where the sessionStorage remains populated even after closing an iframe and opening another one with the same destination. I assumed that the sessionStorage would be reset and start afresh each time. The iframe is contained ...

Trouble encountered while setting up CORS in Spring Boot and ReactJS

Having thoroughly reviewed all the MDN documentation on CORS, I am attempting to retrieve resources from a Spring Boot server at localhost:8080 within a ReactJS application at localhost:3000. However, I am not receiving the expected response. Here is the c ...

Rendering external HTML content within a React component can be achieved by utilizing parsing techniques

In my React application, I have a component that receives HTML content as a string field in the props from an API call. My objectives are: To render this HTML content with styles applied. To parse the content and detect "accept-comments" tags within sec ...

Vue Progressive Web App pre-caching routes for improved performance

Seeking guidance to ensure I'm on the right track. I've developed a simple web application using Vue CLI with PWA support. Everything appears to be functioning properly, including the install prompt. My objective is to cache certain pages (route ...

Issue with PrimeNG Carousel width on mobile devices

Currently, I am in the process of developing a system interface with Angular and PrimeNG specifically for mobile devices. The main requirement is to have a carousel to display a set of cards. After evaluating different options, I decided to utilize the ngP ...

What is the optimal order for executing JavaScript, jQuery, CSS, and other controls to render an HTML page efficiently?

What are some recommended strategies for optimizing webpage loading speed? What key factors should be taken into consideration? ...

Step-by-step guide to implementing a user-friendly search input field using the powerful AngularJS material design framework

I am searching for an effortless method to implement a feature similar to the expandable search text field in angular-mdl. By clicking on a search button, it will expand into a text field. <!-- Expandable Textfield --> <form action="#"> < ...

Semantic UI (React): Transforming vertical menu into horizontal layout for mobile responsiveness

I have implemented a vertical menu using Semantic UI React. Here is the structure of my menu: <Grid> <Grid.Column mobile={16} tablet={5} computer={5}> <div className='ui secondary pointing menu vertical compact inherit&apos ...

Employing CSS animations to elevate div elements

Currently, I am working on animating a table of divs and trying to achieve an effect where a new div enters and "bumps up" the existing ones. In my current setup, Message i3 is overlapping Message 2 instead of bumping it up. How can I make Messages 1 and 2 ...

Tips for removing a single item from a list in ReactJS one by one

There seems to be an issue with the deletion functionality in my project. When a user tries to delete a row, sometimes only that specific row is deleted, but other times when there are only two rows left and one is deleted, the data toggles and replaces it ...

Changing the image source dynamically at runtime using JavaScript and jQuery

Is it possible to dynamically change the source of an image using jQuery during runtime? I have set up a jsfiddle to demonstrate my question. I am attempting to load the image specified in the variable $newsrc when a button is clicked. However, I am unsure ...

"Clicking on a Java Radio Button dynamically updates the text of a Button in

I'm looking for assistance with my Java Calendar project for my Programming II class. I have created a 6 x 7 grid of buttons and implemented a method that changes the button text based on the selected month from a radio button. The functionality works ...

Parsing string to JSON object and extracting specific information

In my code, I have a variable named "response" that contains the following string: {"test": { "id": 179512, "name": "Test", "IconId": 606, "revisionDate": 139844341200, "Level": 20 }} My goal is to extract the value of the id key and store ...

What could be causing the inability to 'GET' a page on an express app?

As a beginner in web app development, I've been self-teaching Node Express. While I've had success running simple express apps on Cloud9 environments, I'm facing difficulties getting them to work with VS Code. The server starts up fine, but ...

Restructure an array of objects into a nested object structure

I have a list of task items that I need to organize into a structured object based on the ownerID var tasks = [ {taskID: "1", title: "task1", ownerID: "100", ownerName: "John", allocation: 80}, {taskID: "2", title: "task2", ownerID: "110", ownerNam ...

Blend the power of Dynamic classes with data binders in Vue.js

Recently, I've been working on a v-for loop in HTML that looks like this: <ul v-for="(item, index) in openweathermap.list"> <li>{{item.dt_txt}}</li> <li>{{item.weather[0].description}}</li> <li>{{item.w ...

Steps for utilizing response data as parameters for useInfiniteQueryHere is how you can make

On the specific page where I am implementing useInfiniteQuery const { data, error, fetchNextPage, hasNextPage, isFetching, isFetchingNextPage, status } = useInfiniteQuery( ['posts', searchState], ({ pageParam = 1 }) => post.search({ . ...

Creating a Dropdown Filter using Vanilla JavaScript

I am currently working on a project for one of my college courses, which involves creating a dropdown list filter using pure JavaScript to filter a grid of images in HTML/CSS. The main challenge I am facing is that this filter needs to be able to work with ...