0

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.

3xCh1_23
  • 1,491
  • 1
  • 20
  • 39

1 Answers1

0

OK I figured it out. Nothing wrong with the code. The response needs to be JSON. It works with "https://api.npms.io/v2/search?q=vue", does not work with "https://www.google.com/".

3xCh1_23
  • 1,491
  • 1
  • 20
  • 39