Transferring information to a subordinate view

I'm working on developing a single-page application and need to transfer data to a child view.

After fetching the API using Axios, I am able to successfully log the data in the console. However, when trying to display the data in the child view, I encounter an error message stating "[Vue warn]: Property or method 'outputs' 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." You can find more information here.

app.js
/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

window.Vue = require('vue');

/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i)
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';


import '../../node_modules/nprogress/nprogress.css';

const axios = require('axios');


Vue.use(VueRouter);



const app = new Vue({
    el: '#app',

    data: function() {
        return {
            outputs: []
        }
    },


    mounted() {
        axios.get('/api/output')
            .then((response) => {
                this.outputs = response.data;
                console.log(this.outputs);
            })
            .catch((err) => {
                console.log(err);
            });



    },

    router:new VueRouter(routes),

});
Outputs.vue
<template>
    <div><div class="text-grey-darkest font-normal uppercase text-3xl font-bold leading-none mb-3">Outputs</div>
    <ul>
        <li v-for="(journal_id) in outputs" v-text="journal_id"></li>

    </ul>
    </div>
</template>

<script>

    export default{};
</script>

data structure JSON

Rendering the data in an Li in the child view.

Answer №1

It is necessary to integrate the data into the component, rather than the base Vue instance.

For example, within Outputs.vue

<template>
    <div>
        <div class="text-grey-darkest font-normal uppercase text-3xl font-bold leading-none mb-3">Outputs</div>
        <ul>
            <li v-for="(journal_id) in outputs" v-text="journal_id"></li>
        </ul>
    </div>
</template>

<script>
    const axios = require('axios');

    export default {
        data() {
            return {
                outputs: [],
            };
        },
        mounted() {
            axios.get('/api/output')
                .then((response) => {
                    this.outputs = response.data;
                })
                .catch((err) => {
                    console.log(err);
                });
        }
    }; 
</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

Leveraging the power of context to fetch data from a store in a React component within the Next

I'm having trouble with the title in my React project, and I'm new to React and Nextjs. When trying to fetch data from my dummy chat messages, I encountered this error: × TypeError: undefined is not iterable (cannot read property Symbol(Sy ...

Unable to open file after downloading via AJAX

I am facing an issue while trying to download a file using an Ajax request. Although the file is successfully downloaded, I am unable to open it. I am seeking assistance with the provided details below. Thank you. On a JSP page, there is a list ...

What is the best way to implement autoplay sound on a JavaScript webpage?

I'm currently working on a web system aimed at monitoring values from a database, and I have the requirement to trigger a sound alert when a specific range of values is received. Despite trying various examples found online, none of them have been suc ...

jQuery sends ajax success to input type number

I am encountering an issue with the ajax success loading function when using input type number. Interestingly, when I switch the input type to text, it works perfectly fine. However, once I change the input type back to number, the loading ceases. <s ...

Bring in JS into Vue from the node_modules directory

Apologies for my limited knowledge in this area, but I am currently working on integrating and importing This Grid System into my Vue project. However, I am facing some challenges. Typically, I import plugins like this: import VuePlugin from 'vue-plu ...

Sticky header/navigation bar implementation in React Native for consistent navigation across views

Currently, I am working on creating a consistent navbar/header for my React Native app. At the moment, when I switch between views in my code, the entire interface changes. It functions properly, but the navbar/header scrolls along with the view, making i ...

Tips for customizing the border radius style of the menu in Vuetify's v-autocomplete component

I am looking to customize the appearance of the drop-down list in the v-autocomplete component by adding a border-radius style, as depicted in the image below. The current design I have achieved closely resembles the visual shown below. Previously, I app ...

Executing JavaScript function from external SVG file globally

I am working on an HTML page that includes an external JavaScript module <script type="text/javascript" src="js/js.js"></script> and also an external SVG map called "img/map.svg". My goal is to create clickable objects on the map that will t ...

The callback response in Node's exec function is behaving incorrectly

When I have a route handling a URL post request, I am running an exec on a bash command. Strangely, the console.log is working fine indicating that the bash command ends and the callback is triggered. However, for some reason, the response fails to send ...

Toggle button to create a fade in/out effect

Below is the HTML code snippet: <html> <head> <Script type = "text/javascript" src = "CprMdlrSrch.js"></Script> <link type="text/css"rel="stylesheet"href="CprMdlrSrch.css"/> </head> <body> <div id=" ...

Iterate over an array of objects to showcase the property values within an HTML tag using JavaScript

I am a beginner in JavaScript and I am currently working on an exercise. My goal is to iterate through an array of objects within another object, map the index values from one object to the id values in another object, and based on that, perform a certain ...

Issues encountered with sending post requests to a yii2 application when using Angular4

After implementing the following code: this.http.post('http://l.example/angular/create/', {name: 'test'}).subscribe( (response) => console.log(response), (error) => console.log(error) ); I encountered an error on ...

Is there a way to display current data in angularJS based on the current time?

My database contains timestamps like 2016-12-30 00:30:10 which I retrieve using the $http module in Angular. Below is a snippet of my Angular code: angular .module('sampleApp') .controller('ReportCtrl', ReportCtrl) ...

When I try to open my modal in Electron by clicking on the button, it doesn't work

I was expecting the modal to open by clicking on the Edit button within #app, but it doesn't open at all! I am unsure if there is an issue with my JavaScript logic or my HTML code! When attempting to use a function for the Modal, it still does not wo ...

What is the reason behind the necessity of adding an extra slash when reloading the page and controller in AngularJS by using $location.path()?

In AngularJS, when you use $location.path() and pass the same URL as the current one, it does not reload the page and controller. However, if you add an extra slash at the end of the URL like this: $location.path('/currentURL/'); it forces a re ...

Steps to include a personalized function in a Mongoose Model

One way to extend Mongoose is by adding methods to documents. Here's an example: const userSchema = new mongoose.Schema({ balance: Number }) userSchema.methods.withdrawBalance = function(amount){ const doc = this doc.balance = doc.balance - amou ...

Encountering a SOCKET_TIMEOUT issue while setting up a new project using Vue CLI (npm error

I'm in the process of setting up a new Vue project using vue create vue-first-app and I encountered an error. I attempted to extend the timeout by running npm install -timeout=9999999. Additionally, I tried clearing the npm cache with npm cache clean ...

Interacting with YouTube Data API without requiring user input

I'm currently developing a music website that enables users to create YouTube playlists. Initially, I experimented with JavaScript: https://developers.google.com/youtube/v3/code_samples/javascript The procedure involves an initial authorization ste ...

What could be causing me to have to click the button twice in order to view my dropdown list? Any suggestions on how to

I am facing an issue where I have to click twice on the "Action" button in order to see my dropdown list. How can I resolve this? Is there a way to fix it? $(document).ready(function() { $(".actionButton").click(function() { $dropdown = $("#cont ...

Transferring information using "this.$router.push" in Vue.js

I'm currently developing a restaurant review project using Django REST and Vue.js. To ensure uniqueness, I have adopted Google Place ID as the primary key for my restaurants. The project also incorporates Google Place Autocomplete functionality. The ...