仅以此文记录这傻逼问题
vue代码
<script setup>
import request from '../utils/request'
import { ref } from 'vue'
import axios from 'axios'
let arrayA=ref([])
function getdata(){
axios({
methods: 'get',
url: '/getdata/', //此处写成 url:'/getdata'将报错
baseURL:"http://127.0.0.1:8000",
}).then(function (response) {
console.log('获取数据response:' + response)
console.log(response.data)
}).catch(function (error) {
console.log(error)
})
}
</script>
<template>
<main>
<h2>homeview</h2>
<button @click="getdata">后端请求数据</button>
</main>
</template>
Access to XMLHttpRequest at 'http://127.0.0.1:8000/getdata' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
在后端配置好跨域中间件后注意url的写法!!!!!