无法通过Vue发送GET请求 [英] Can't send GET Request with Vue

查看:94
本文介绍了无法通过Vue发送GET请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Vue组件

<template>
  <v-container>
    <div id="app">
      {{ posts }}
      <v-divider></v-divider>
      {{status}}
    </div>
  </v-container>
</template>

<script>
  import axios from "axios";

  export default {
    el: '#app',
    data () {
      return {
        status:null,
        posts: []
      }
    },
    mounted () {
      axios
          .get('http://localhost:8080/uebungen')
          .then(response =>{
                this.posts=response.data
              }
          )
    }
  }

</script>

我想在Spring程序上发出一个get请求,我可以与后端完美地工作,我可以从python或邮递员发送一个get请求,而没有任何问题,但是如果我使用Vue axios发送一个get请求,则会出现这个奇怪的错误在我的浏览器中.我对Vue还是很陌生,希望我不会弄乱一些基础知识.我不会在vue或我的spring程序中出现错误,因为vue不会显示任何内容

I want to make a get request on my Spring Programm, I can work with my backend perfectly, i can send a get request from python or postman without any problems, but if i send one with Vue axios i got this weird error in my browser. I am pretty new to Vue, I hope i haven't messed up with some basics. I wont get an error in vue or in my spring programm, in vue it just won't show anything

推荐答案

这是cors错误,由于安全问题,您的浏览器阻止了响应.

This is cors error, your browser is blocking the response due to security concerns.

跨源资源共享(CORS)是一项允许服务器放宽同源策略.这用于显式允许一些跨域请求,而拒绝其他请求.

Cross-Origin Resource Sharing (CORS) is a standard that allows a server to relax the same-origin policy. This is used to explicitly allow some cross-origin requests while rejecting others.

可以做什么:

  • 如果您是后端开发人员,请在响应标头中允许您的站点URL(发出请求的位置)(FE).
  • 如果您无权访问后端,则可以使用以下命令禁用CORS:为您的设备浏览器扩展.

详细了解 CORS

这篇关于无法通过Vue发送GET请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆