Using Axios to facilitate communication between API and Interface

I am facing a challenge in establishing communication between the API and the Interface. To explain further: I send a JSON file from the API, but I am unable to retrieve it and display it in the Interface. The JSON structure is simple: {"name": "joe"}

My code for the API can be found at (http://localhost:8080/route1)

const jsontest = require('../models/test'); 
.
.
router.post('/', (req, res) => {
       res.send(jsontest);  
        });
module.exports = router;

On the interface side (http://localhost:8081/)

<template>
.
.
  <v-btn x-large color="grey"  class="d-flex align-start flex-column mb-6" @click="getData" 
 >Start</v-btn>


      <div v-if="todos">
        <li>{{todos}}</li>
      </div>
</template>

Continued with:

<script>

import axios from 'axios';
const WorkersURL = 'http://localhost:8080/route1';

export default {
 data() {
   return{
     drawer: false,
      todos:''
   }
 },  

 methods: {
 getData: function()
 {
    axios.post(WorkersURL)
    .then(response => {
      console.log(response.data);
      this.todos = response.data.name;    
          })
    .catch(e => {
      this.errors = e
    });

  }
},
 mounted() {
     this.getData;
  }
}
</script>

Any assistance on this issue would be highly appreciated.

Answer №1

Make sure to include res.json() in your server logic:

router.post('/', (req,res)=>{
  res.send(jsontest);  
});

Additionally, eliminate the empty brackets from axios.post(WorkersURL,{})

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

One of a kind v-select options specifically tailored for each row in a v-data

I need assistance in creating a table with a v-select for each row of the "available" column to allow users to select either "In stock" or "Unavailable". How can I achieve this using the table provided below, which includes the following data? Table: < ...

Issue with Jquery event not triggering correctly following ajax data retrieval

This script uses jQuery and Ajax to populate a navigation bar with categories and subcategories dynamically. The first unordered list is static, while the second one is populated after receiving data via Ajax. There are some jQuery events that need to be i ...

Configuring vue-jest: Does anyone know how to set up aliases for template/script src attributes in Vue?

Dependencies: "@vue/cli-plugin-unit-jest": "^4.5.13", "@vue/test-utils": "^1.2.1", "vue-jest": "^3.0.7" I am dealing with an application that utilizes an alias (referred to as "foo") de ...

Issue with AngularJS: The select dropdown fails to update the selected option when the bound scope variable changes

I am facing an issue with a select control in my Angular app. The options for the select are generated dynamically from an array of objects in the scope. When I try to pre-select a specific option on app init by changing a bound variable on the scope, it d ...

Multi-object retrieval feature in Material Dialog

I am encountering an issue with Material Dialog when confirming the action to "remove row" in a table. Initially, removing from the dialog works fine and deletes a row. However, after closing the dialog and re-calling it for the second time, the removal ac ...

Dividing a collection of URLs into smaller chunks for efficient fetching in Angular2 using RxJS

Currently, I am using Angular 2.4.8 to fetch a collection of URLs (dozens of them) all at once. However, the server often struggles to handle so many requests simultaneously. Here is the current code snippet: let collectionsRequests = Array.from(collectio ...

Implementing Pagination in Vue: How to Make it Work with Response Data

I am looking to integrate pagination from the response data into my existing code, while also incorporating filters. JavaScript var entriesList = new Vue({ el: "#post-list-template", data: { posts: [], categories: [], cu ...

How to retrieve the $0 element using Python Selenium

There is an unnamed element I can only access with a dollar sign: console.log($0); "100" In Python Selenium, how can I retrieve this element? I attempted the following: my_value=driver.find_element(By.NAME,"$0") However, it resulted i ...

When using EventBus in Vue.js with dynamic elements, the $off method removes event listeners for all reused components at once, rather

I am encountering an issue with a dynamically generated component that can be mounted multiple times on a page simultaneously. When there are 10 food items returned from a feed, there are 10 components created. Each FoodItem component has its own event bus ...

Tips for embedding Jquery code within Vuejs applications

Trying to code a Vue.js Navbar that changes color when scrolling using Jquery and CSS script. It works, but I encountered an error with Vue.js not supporting the syntax '$' after page refresh, resulting in a "$ not defined" error message. As a ne ...

What is the best way to alternate between displaying HTML content with v-html and plain text in Vue.js?

I need a way to switch between v-html and plain text in Vue.js v2. Here's what I have so far: HTML <div id="app"> <h2 v-html="html ? text : undefined">{{html ? '' : text}}</h2> <button @click=&qu ...

Comparison of various approaches for invoking JavaScript/jQuery functions

Do the following examples have a performance variation? Example 1: $(window).on('resize', abc); function abc(){ //some abc code } Example 2: $(window).on('resize', function(){ //some abc code }); If so, what are the positives ...

Troubleshooting Error: "Custom Vue component installation in Laravel 5 is not found in the npm registry"

We have decided to integrate Vue.js into our Laravel technology stack. In the app.js file, we have included the following Vue component: App.js file Vue.component('main-chart-of-accounts', require('chart_of_account.vue').default); Th ...

Using Javascript to prevent css from changing the display

I want to make some CSS adjustments to a single element using a single script, but I want all the changes to be displayed at once. For example: $("#someelement").css({width:"100%"}); //this change should not be displayed $("#someelement").width($("#someel ...

Is it possible for setTimeout to not increment the counter in node.js?

Even though the loop is executed multiple times in the Node.js program below, why does the control not exit the loop? I made sure to increment the value of i within setTimeout instead of forgetting to do i++ in the for loop. function abc () { for(var ...

The getElementById function can only select one option at a time and cannot select multiple options

I'm having an issue with a JavaScript function that is supposed to allow me to select multiple options, but it's only selecting the first one. Here is the JavaScript code: function index(){ var a="${staffindex}".replace("[",""); ...

What is the method for accessing an app from a file other than server.js?

I am dealing with two different files: file1.js const app = express(); require('./file1/config/customConfigurations').customSettings() .then((settings) => { app.locals.customSettings = settings; console.log(app.locals.customSettings) ...

Universal capability for selecting all items in a table

Here we have a snippet of code from my grid (CRUD) component: <template> <table class="MyComponent table"> <thead> <tr> <th width="30px"> <b-form-checkbox v-model="allC ...

Conceal a child div through the use of AJAX technology

Utilizing AJAX, I am loading pages on my website. Each page consists of two common div elements - the header div and the content div. When navigating from one page to another, I load the content div of the next page into the current page using the followin ...

Ways to substitute a single parameter within Vue.js router

We are working on a complex multi-level multi-tenant application, where the hostname is used to identify the 'supplier' account and the customer account is included in the URL structure. For example, our routes are structured like this: /:local ...