Attempting to fetch JSON data in a VueJS component called "prijzen" using axios for the API call

Just starting out with Vue and attempting to fetch JSON data from a REST API called JSON placeholder. Encountering the error message:

"Uncaught ReferenceError: Prijzen is not defined at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/layout/Prijzen.vue?vue&type=script&lang=js&:16) at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/layout/Prijzen.vue?"

After receiving this error, I inspected index.js where Prijzen is included... here's the relevant code snippet:

import Vue from 'vue'
import Router from 'vue-router'

// Containers
const TheContainer = () => import('@/containers/TheContainer')

// Views
const Dashboard = () => import('@/views/Dashboard')
const Prijzen = () => import('@/views/layout/Prijzen')
const Login = () => import('@/views/layout/Login')

Vue.use(Router)

export default new Router({
  mode: 'hash', 
  linkActiveClass: 'open active',
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '/',
      redirect: '/dashboard',
      name: 'Home',
      component: TheContainer,
      children: [
        {
            path: 'dashboard',
            name: 'Dashboard',
            component: Dashboard
        },
        {
          path: '/login',
          name: 'Login',
          component: Login
        },
        {
          path: '/layout/prijzen',
          name: 'Prijzen',
          component: Prijzen
      }
      ]
    },
  ]
})

The above code seems fine regarding Prijzen. Now let's take a look at how the Prijzen component is structured:

<template>
  <div id="Prijzen">
    {{ prijs }}
  </div>
</template>

<script>
import axios from 'axios';
import PrijsItem from './PrijsItem.vue';

export default {
  name: 'Prijzen',
  components: {
    PrijsItem
  },
  props: ["PrijsItem"]
}
</script>

I've used {{ prijs }} in the template and also made mention of it in my main.js file where it is involved in an axios get request as shown below:

import 'core-js/stable'
import Vue from 'vue'
import CoreuiVue from '@coreui/vue/src'
import App from './App'
import router from './router/index'
import { iconsSet as icons } from './assets/icons/icons.js'
import store from './store'

Vue.use(CoreuiVue)

new Vue({
  el: '#app',
  router,
  store,
  //CIcon component documentation: https://coreui.io/vue/docs/components/icon
  icons,
  template: '<App/>',
  components: {
    App,
    Prijzen
  },

  new:({
    let: '#Prijzen',
    data () {
      return {
        prijs: null
      }
    },
    mounted () {
      axios
        .get('https://jsonplaceholder.typicode.com/posts')
        .then(response => (this.prijs = response))
    }
  })
})

Answer №1

Have you confirmed that the Prijzen.vue file is located in the views/layout directory? The error message seems to indicate that it cannot locate the file where it is expected.

Another issue:

{{ prijs }}

This code is present in the template, but the variable "prijs" has not been defined. Additionally, the PrijsItem component has been imported but is not being used, which may trigger linting errors.

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

Ways to efficiently display elements in a grid in real-time

Attempting to design a layout where each row consists of 3 cards using Bootstrap's Grid layout for responsiveness. The challenge lies in the fact that the card data is stored in JSON format, and the length of the JSON Object array may vary, leading t ...

What is the best way to adjust the size of a Google Map container based on the radius of a circle?

I have successfully integrated Google Maps v3 into my website. However, I am faced with the challenge of resizing the map according to the radius of a circle. I want the map to be covered by the circle. Currently, my container's dimensions are heigh ...

How can you receive a file through AJAX response?

I have a standard Ajax function that I regularly use to call a specific function within my node.js server. This particular function is responsible for retrieving a file (usually in xls format) from the server and streaming it back to the client. Below is ...

Does jQuery UI Layout have compatibility issues with jQuery version 3.3.1?

jQuery UI Layout is compatible with older versions of jQuery, but not with newer versions... Here is a working example: <html> <head> <script src="http://layout.jquery-dev.net/lib/js/jquery-1.4.2.js"></script> <script ...

Searching for a specific field within an array in a nested subdocument in MongoDB: What you need to know

I am having trouble retrieving lookup data for an embedded array within a document. Below is a snippet of the data: { "_id": "58a4fa0e24180825b05e14e9", "fullname": "Test User", "username": "testuser" "teamInfo": { "chal ...

JavaScript - Sending Form Data with Local Time

I want to automatically submit a form at a specific time of day The form should be submitted every day at "15:30:00" Here is the JavaScript code I have written: <script type="text/javascript> function initClock() { var now = new Date(); var h ...

Issues arise when implementing Django templates in conjunction with jQuery

Here is an example of a Django template that I am working with: ... <div class="row"> <div class="col-lg-12"> <button type="submit" class="btn btn-primary" id="related"}>KIRK</button> </div> </div> . ...

What steps can I take to guarantee that a directive's link function is executed prior to a controller?

Our application features a view that is loaded through a basic route setup. $routeProvider .when('/', { template: require('./views/main.tpl.html'), controller: 'mainCtrl' }) .otherwise({ re ...

What is the best approach for dynamically updating JSON values using user input in jQuery?

I have implemented a feature where users can enter values into 3 text boxes and upon clicking the add button, these values are added to a new JSON object and displayed in a table. Additionally, users can edit specific fields in the table which should updat ...

What is the best way to ensure that the input submit element is only visible after the input checkbox element has been checked?

For a school project, I am attempting to create a simulated reCAPTCHA box. Although my code is complete, I would like the functionality to submit your response from the input fields above only after selecting the reCAPTCHA checkbox. Upon researching, it ap ...

Encountering a "DOM Exception 11: InvalidStateError" when attempting to use websocket.send

I encountered the following error message: DOM Invalidate exception 11 This error is coming from the code snippet below, but I'm having trouble identifying the root cause. /*The coding style may appear pseudo-stylish with potential syntax errors*/ ...

Unexpected button behavior sparked by Vue.js

Check out this fiddle I created: https://jsfiddle.net/frvuw35k/ <div id="app"> <h2>Vue Event Test</h2> <form @submit.prevent> <div class="form-group row"> <div class="col-sm-12 i ...

The compatibility of jQuery is not guaranteed in a file obtained through a Java select include statement

I am encountering an issue with a simple form that includes a PHP file in a div when changed, but for some reason, jQuery does not load when placed in the included file. Can someone please help me understand why this is happening? <select name=&a ...

What is the best way to connect an image using Flask and javascript?

I'm attempting to insert an image into a card using JavaScript, structured like this: console.log(account_name); document.getElementById("list_of_datasets").innerHTML += ` <div class="col-lg-4 d-flex align-items-stret ...

Can a complete form be encapsulated within a single AngularJS directive?

While I have come across several instances of individuals utilizing a blend of HTML and directives to craft an AngularJS form (as seen here), my goal is to develop a self-contained widget. This widget would encompass all the necessary HTML for the form w ...

Issues encountered when attempting to run a local Dockerized Vite + Vue frontend deployment

Trying to utilize docker-compose for running a local FE Vite + Vue project. With references from various tutorials and posts, like this one here. The docker-compose setup seems to be functioning well, starting the FE server but not loading in Chrome. Docke ...

Displaying a notification in React when the array of objects is empty

I need to create a notification based on whether my object contains any data or not. Initially, I store the data in a state called "data" and set it to null. When I receive data from the server, I update the data state with the returned data. If the data ...

How can you utilize Angular Signals in combination with HostBinding to dynamically update styles?

Within a component called app-test, the following code is present: @Input({ transform: booleanAttribute }) reverse: boolean = false; @HostBinding('style.flex-direction') direction: string = this.reverse ? 'column-reverse' : &ap ...

Enhancing a popup with animated effects

I have been working on a popup that I want to add a subtle animation to. A fade effect seems like the perfect solution. Here is the code for the button: <a href="javascript:void(0)" onclick="document.getElementById('back_overlay').style.disp ...

Unable to use href attribute as intended

HTML: <a id="Switch">Click here to switch</a> <a href="image1_large.png" class="mainA blade"> <img id="mainImage" src="image1.png"/></a> Javascript: <script> $(function() { $('#Switch').click(functio ...