Trying to get a simple GET response in Vue.js by pressing a button (with axios), does not work

I have tried suggestions such as:

Print response from http GET request using axios in vue.js?

Vue.js + Axios not assigning response Get response data from axios in vue.js

simple typescript function with axios get call does not work

None have solved the issue.

This is the code that I have (port 2020, doesn't work with 8080 either):

    <template>
    <p>{{ testResponse }}</p>
      <button v-on:click="sendRequest">Get Data</button>
    </template>
    
    <script>
    const axios = require("axios");
    
    export default {
      name: 'Auth',
      created: function () {
      },
      data: function () {
        return {
          testResponse:'init',
        };
      },
      beforeMount() {},
      methods: {
        sendRequest() {
          this.getEvents("https://www.google.com");
        },
        async getEvents(url) {
          axios
              .get(url)
              .then(response => {this.testResponse = response.data})
        },
      }
    };
    </script>
    </template>

Pressing the button does not do anything. The GET does get sent, servers process the GET, but no data is obtained from it... What am I doing wrong ?

Edit: removed the junk.



Read more here: https://stackoverflow.com/questions/64412606/trying-to-get-a-simple-get-response-in-vue-js-by-pressing-a-button-with-axios

Content Attribution

This content was originally published by Damir Olejar at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: