Tips for showcasing the outcome of an SQL query on an HTML page

I need assistance with displaying the output of an SQL query on my website. My server-side is using NodeJs and client-side is VueJs.

After querying my database, I received the following result:

[
  {
    Time_Stamp: 2019-12-09T11:54:00.000Z,
    Time_Stamp_ms: 136,
    CadenceInstant195: 660,
    TempsCycle: 5388,
    Totalisateur195: 0,
    NCPoste1: 87,
    NCPoste2: 2649,
    NCPoste4: 503,
    NCPoste6: 1821,
    NCPoste7: 5590,
    EtatMachine: 0
  },
  {
    Time_Stamp: 2019-12-09T11:55:00.000Z,
    Time_Stamp_ms: 200,
    CadenceInstant195: 660,
    TempsCycle: 5395,
    Totalisateur195: 0,
    NCPoste1: 87,
    NCPoste2: 2649,
    NCPoste4: 503,
    NCPoste6: 1821,
    NCPoste7: 5590,
    EtatMachine: 0
  }
]

The result is stored in a variable in my JS file like so:

window.onload = function () {
    var consultation = new Vue({
        el:"#consultation",
        data: {
            data : []       
        },
        methods: {
            load: function() {
                this.$http.get("/data?startDate="+this.filtres.startDate+" "+this.filtres.startHour+"&endDate="+this.filtres.endDate+" "+this.filtres.endHour).then(function(response) {
                    this.data = response.body;
                    console.log(this.data);
                })
            }
        }
    })
}

The load() function executes the query to the database.

Here's my HTML code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="css/style.css">

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <title>Historique</title>
</head>
<body>
    <div id="consultation">
            {{todos}}
    </div>
    <script src='/AffichageHistorique/js/vue.js'></script>
    <script src='/AffichageHistorique/js/vue-resource.min.js'></script>
    <script src='/AffichageHistorique/js/historique.js'></script>
</body>
</html>

Now, I'm struggling to display the query result on my webpage. Placing {{data}} into my HTML isn't showing anything. Any suggestions?

Answer №1

To display your result data in HTML, you should iterate through the array data using a loop. Make use of v-for directive to loop through the result data

  <ul id="example-1">
  <li v-for="item in items">
    {{ item.message }}
  </li>
</ul>

var example1 = new Vue({
  el: '#example-1',
  data: {
    items: [
      { message: 'Foo' },
      { message: 'Bar' }
    ]
  }
})

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

Troubleshooting a TypeScript error when trying to access an imported service in Angular 2

I've been working on creating a form that allows users to input required details, which will trigger a server call and save the information. However, no matter what I try, I keep encountering the following error: ORIGINAL EXCEPTION: TypeError: this.po ...

Issue: .catch(error) function in Node / Express not returning as expectedDescription: After

I'm currently developing a REST API and focusing on effectively managing all error scenarios. Upon successful completion of the API call, I make sure to return the success object to the calling function and then send the response to the client. Howev ...

Is there a way to automatically clear the text field value after submitting?

Greetings everyone, I'm looking for guidance on removing the text field content once I click submit. I have a button labeled "senden" and my goal is to clear the text fields and uncheck the checkbox after clicking this button. I've attempted se ...

Using Node.js and Express with MySQL to store documents (outcomes)

I recently developed an Express App using Node.js Express v4.16.2 MySQL v2.15.0 In my app, I have configured MySQL as a Document Store Columns id: integer value: JSON When querying the MySQL Database with mysql, I receive the following result: Ro ...

What is the best way to display components in VueJS?

I am looking to dynamically render a component based on my variables with the following code: <div>{{ auth ? <AuthCorrect /> : <AuthIncorrect /> }}</div> However, my application is currently rendering it like this: {{ auth ? auth ...

How do I go about updating my code for welcome messages from discord.js v12 to v13?

While watching a YouTube tutorial on welcome messages, I decided to copy the entire code. However, when I tried using this code with discord.js v13, it didn't work. Strangely enough, everything seemed to function perfectly fine with discord.js v12. In ...

Leverage variables in Ajax to retrieve the data of an HTML element

Seeking assistance in converting multiple lines into a single for loop. var optie1 = ""; if($('#form #optie1_check').is(':checked')) { optie1 = $('#form #optie1_naam').val(); } var optie2 = ""; if($('#form #optie2_ch ...

Mastering the art of correctly utilizing splice and slice

I'm having trouble identifying the issue in my code. Despite reading numerous articles on slice and splice, I am unable to achieve the desired outcome in my Angular project (not using both methods simultaneously). The results are not as expected. Belo ...

Interactive section for user input

I am looking to add a commenting feature to my website that allows for dynamic editing. Essentially, I want users to be able to click on an "Edit" span next to a comment and have it transform into an editable textarea. Once the user makes their changes and ...

Enhance your application by utilizing additional hooks in the Context API

I'm exploring API and react hooks and have a query related to dispatching API fetch to ContextAPI component. Is there a way to consolidate all useState hooks into a single ContextAPI component? The objective is code refactoring by breaking it down int ...

Dynamic calendar with flexible pricing options displayed within each cell

I've been wracking my brain over this issue for quite some time now, but still can't seem to find a solution! Is there a React Calendar out there that allows for adding prices within the cells? I simply want to show a basic calendar where each c ...

Steps to display a text box once the dropdown list is updated

I have a dropdown menu with two options <div class="form-group"> <span class="col-sm-4 control-span">Member Type</span> <div class="col-sm-8"> <select class="form-control" id="membertype" name="me ...

Use of absolute positioning resulted in the disappearance of the element

Can anyone assist with resolving the issue I am encountering? I currently have three nested divs as follows: <div class="section"> <div class="parent"> <div class="child"> Some random text. </div> </div> </div> To adj ...

I am currently having trouble with req.query not functioning correctly within Next.js for reading query parameters

I am facing an issue while working with a REST API in Next.js 13. I have created the API, which can be accessed at http://localhost:3000/api/portfolio. However, when I try to filter the data using query parameters like http://localhost:3000/api/portfolio?s ...

Strategies for managing rate-limited API services in React/Node.js: Handling ReferenceErrors

Hey there! I'm new to the world of React and NodeJS, and right now I'm navigating my way through dealing with a rate-limited API service. My plan is to have NodeJS fetch data from this API every half an hour, then send it to my "/youtube" endpoin ...

Avoid production build warnings in Vue.js without the need to build the code

Experimenting with vuejs, I decided to use it for a simple page even though I could have achieved the same without any framework. Now, my project is nearly production ready. The only issue is that it's just a single js and html file, but it shows thi ...

The VueJs input file @change event only triggers once in Chrome after the first call

Here is the code snippet I am currently working with: HTML: <input id="task-message-input-upload" type="file" ref="file" @change="handleFileUpload($event)" /> Javascript : data() { return { uploadedFiles: [], show ...

Assigning a click event to an element within CKEditor

Looking to add a click event to an element in ckeditor4-angular for custom functionality <div class="fractional-block" id="fractional-block"><span>5</span><svg height="5" width="100%"><line ...

Certain words in {{$t('msg')}} may have a distinctive format

Creating a webpage that needs localization, I have to store paragraphs in variables: index.vue <div class="descrip"> <p class="dTitle">{{$t('message.instructionTitle')}}</p> ...

Javascript alert: forgetting to add ; before statement causes SyntaxError

Seeking to incorporate a post-it application into my django website using Javascript/JQuery. Came across a tutorial and attempted to add it to my script, but encountered a SyntaxError: SyntaxError: missing ; before statement post-it.js:2:19 Not be ...