如何解决试图通过按下按钮使用axios在Vue.js中获得简单的GET响应不起作用
我尝试了以下建议:
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
没有人解决这个问题。
这是我拥有的代码(2020端口,也不适用于8080):
<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>
按按钮不执行任何操作。 GET确实发送了,服务器处理了GET,但是没有从中获得数据...我在做什么错了?
编辑:删除了垃圾。
解决方法
好,我知道了。代码没有错。响应必须为JSON。它适用于“ https://api.npms.io/v2/search?q=vue”,不适用于“ https://www.google.com/”。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。