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.

1 Answer 1

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/".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.