Utilizing JHipster and Vue: A Guide to Displaying Backend Data on the Frontend

I am completely new to working with JHipster and have successfully created my first Endpoint that retrieves the entity "buddy" of the connected user:

@GetMapping("/buddies/view")
    public ResponseEntity<Buddy> getConnectedBuddy() { [...] }

The endpoint is functioning properly, as confirmed by the logs showing that when a connected user visits this page, the controller is triggered, the GET request is successful, and the user data is returned:

Exit: com.mycompany.myapp.web.rest.AccountResource.getAccount() with result = UserDTO{login='haha', firstName='null', lastName='null', email='<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82eae3eae3c2e5efe3ebeeace1edef">[email protected]</a>', imageUrl='null', activated=true, langKey='en', createdBy=anonymousUser, createdDate=2020-12-10T14:27:22.264Z, lastModifiedBy='anonymousUser', lastModifiedDate=2020-12-10T14:27:22.264Z, authorities=[ROLE_USER]}

Now, I want to display this user's data on a page similar to http://localhost:9000/< ENTITY-NAME >/{id}/view. I have successfully duplicated the buddy-details.vue and buddy-details.component.ts files and made the necessary modifications, adding the new page to the "entities.ts" file. Everything is functioning as expected.

However, I am facing an issue where the view page displays the entity-form without any data populated in it. Could you please guide me on how to fetch Backend data using TypeScript?

I believe I need to utilize the buddy.service.ts class but I am unsure of how to proceed.

Edit (additional information):

In my buddy.service.ts, I have implemented the get() method:

  public get(): Promise<IBuddy> {
    return new Promise<IBuddy>((resolve, reject) => {
      axios
        .get(`${baseApiUrl}/view`)
        .then(res => {
          resolve(res.data);
        })
        .catch(err => {
          reject(err);
        });
    });
  }

This method is then called in the self-created buddy-active.component.ts:

import { Component, Vue, Inject } from 'vue-property-decorator';

import { IBuddy } from '@/shared/model/buddy.model';
import BuddyService from './buddy.service';

@Component
export default class BuddyActive extends Vue {
  @Inject('buddyService') private buddyService: () => BuddyService;
  public buddy: IBuddy = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
        vm.getBuddy();
    });
  }

  public getBuddy() {
    this.buddyService()
      .get()
      .then(res => {
        this.buddy = res;
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}

Any assistance provided would be greatly appreciated.

Answer №1

It turned out that the solution was rather straightforward. Despite completing all necessary tasks, I made an error by including the incorrect script in the buddy-active.vue file. If you encounter a similar issue, refer to my initial comment for guidance. However, creating the Java endpoint will be up to you.

Special thanks to Gaël Marziou for steering me in the right path.

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

Unit testing of an expired JWT token fails due to the incorrect setting of the "options.expiresIn" parameter, as the payload already contains an "exp" property

I am having trouble generating an expired JWT token for testing purposes and need some guidance on how to approach it. How do you handle expiration times in unit tests? This is what I have attempted so far : it('should return a new token if expired& ...

Setting the [required] attribute dynamically on mat-select in Angular 6

I'm working on an Angular v6 app where I need to display a drop-down and make it required based on a boolean value that is set by a checkbox. Here's a snippet of the template code (initially, includeModelVersion is set to false): <mat-checkbo ...

Is there a way to ensure that the div of my template spans 100% in width and height?

I'm attempting to make my div 100% in size but I am having trouble achieving it. Here is my code: <template> <div> <Navbar/> <Calendar/> </div> </template> <script setup> import Calendar from &apos ...

Tips for adjusting the background colors on the left and right sides of a page

Currently, I'm figuring out how to enhance the visual appeal of my website by altering the color scheme on both sides of the layout. Here's the snapshot of my struggle: https://i.sstatic.net/7Wkpc.png Here is a snippet of the key code used in my ...

Having trouble importing a TypeScript module from the global node_modules directory

I have a library folder located in the global node modules directory with a file named index.ts inside the library/src folder //inside index.ts export * from './components/button.component'; Now I am trying to import this into my angular-cli ap ...

I am consistently receiving incorrect results when using a scanner to read the number of lines in a text file

I'm having trouble with my code to count the number of lines in a text file. The file I'm testing with has 12 lines, but my output keeps coming out as 0. I've written many similar methods for school assignments before, so I'm really fru ...

When working with Angular 2 and Typescript, a common error message that may be encountered is "TypeError

Currently diving into Angular 2 and encountered a stumbling block while attempting to create a service. Despite my efforts in finding a solution, I seem to be missing something crucial. Error: A problem arises in angular2-polyfills.js:1243 with the error ...

Configuring the React Typescript router to support username-based URLs should be done in a way that does not cause conflicts with other routes

I am looking to display a user's profile on a URL format such as www.domain.com/<userName> and load the component ShowProfile. I want to ensure that terms is not mistaken for a username, so if I visit www.domain.com/terms, I do not want to load ...

I am eager to incorporate the Twilio API into my project, however, I am encountering an error when trying to import Twilio into my TypeScript file

I am currently integrating the Twilio API into my project, but I'm encountering difficulties importing it into my TypeScript file. Interestingly, when I use the API in a JavaScript file, everything works smoothly without any issues. Below are the err ...

Encountering issues with deserializing a JSON instance while attempting to parse a JSON file using Jackson

The data I have is stored in a Json file: [ { "name":"Move", "$$hashKey":"object:79", "time":11.32818, "endTime":18.615535 }, { "name":"First Red Flash", "$$hashKey":"object:77", "time":15.749153 }, { ...

Is your child component releasing data?

Currently, I am facing an issue with my child component where the data changes are not being emitted properly. Here is how I am trying to handle it: <input type="checkbox" value="john" v-model="users" @click="updateUsers"> Upon clicking on the chec ...

What steps can I take to resolve the issue of Laravel comments policy not functioning correctly?

Currently, I am working with Inertia JS. I have developed a forum system that allows users to manage their posts and comments using CRUD operations. In the system, only the creator of a post or comment and the administrator have the privilege to modify or ...

Transfer the data stored in the ts variable to a JavaScript file

Is it possible to utilize the content of a ts variable in a js file? I find myself at a loss realizing I am unsure of how to achieve this. Please provide any simple implementation suggestions if available. In my ts file, there is a printedOption that I w ...

The element 'mat-form-field' is unrecognized in Angular 9 and Material 9.2.0 version

Greetings! I am currently utilizing Angular 9 and here is the code snippet I am working with: The HTML component named "post-create.component.html": <mat-mat-form-field> <textarea rows="6" [(ngModel)]="enteredValue"></textarea> </ma ...

Avoid using <input oninput="this.value = this.value.toUpperCase()" /> as it should not convert the text displayed on the "UI", rather it should send the uppercase value

<input oninput="this.value = this.value.toUpperCase()" type="text" id="roleName" name="roleName" class="form-control width200px" [(ngModel)]="role.roleName"> Even though the UI is changing ...

Laravel: Send users to a personalized 404 page if the parameters provided are not valid

In my application, users have the ability to create papers and view all data in a template. Each paper is assigned a unique "joincode" generated upon creation. To handle the join route, I defined it in my 'web.php' file like so: Route::get(&apos ...

Obtain unfinished designs from resolver using GraphQL Code Generator

In order to allow resolvers to return partial data and have other resolvers complete the missing fields, I follow this convention: type UserExtra { name: String! } type User { id: ID! email: String! extra: UserExtra! } type Query { user(id: ID! ...

Resolving a duplicate class exception with Javassist

Currently, I am using Javassist to insert a line of code into a method's body. This involves a simple modification for adjusting the text color of a label inside the intellij-IDE. However, when attempting to make this modification, I encounter the fol ...

How can you use JsonPath to target a specific attribute and extract only a portion of a record?

These are the specifics of what I am utilizing: <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.0.0</version> </dependency> The JSON example provided i ...

NGRX refresh does not result in any successful actions

Having an issue with loading users into a mat-selection-list within a form. Everything works fine the first time, but upon page refresh, the selector returns 'undefined'. Initially, both GET_USERS and GET_USERS_SUCCESS are triggered (console log ...