gpt4 book ai didi

vue.js - 带有 Axios 的 Vuejs - 使用获取请求时出现 '' 跨域错误

转载 作者:行者123 更新时间:2023-12-05 05:14:17 25 4
gpt4 key购买 nike

<分区>

我的 vue 项目位于这个 url“http://localhost:8081/”。

我想连接到另一个 url“http://localhost:8082/Fleet-App/api/deptList”中的后端。

但是当我打电话时,我收到这样的错误

Failed to load http://localhost:8082/Fleet-App/api/deptList: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access***".

请帮我解决这个问题。

示例.vue

<template>
<b-card>
<h5 class="card-title">Outside Order</h5>
<hr>
<div class="form-group row">
<label for="" class="col-sm-2 col-form-label">Order #</label>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="Default input">
</div>

<label for="" class="col-sm-2 col-form-label">Order Type</label>
<div class="col-sm-2">
<select class="form-control">
<option>Bulk</option>
<option>Container</option>
</select>
</div>

<label for="" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-2">
<select class="form-control">
<option>Active</option>
<option>In-Active</option>
</select>
</div>
</div>

<div class="form-group row">
<label for="" class="col-sm-2 col-form-label">Order Date</label>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="DD-MMM-YYYY">
</div>
</div>
</b-card>
</template>

<script>
import {AXIOS} from '../../components/http-common'

export default {
name: 'order',
mounted(){
AXIOS.get('/deptList')
.then(response => {
console.log(JSON.stringify(response.data))
})
.catch(e => {
this.errors.push(e)
})
}
}
</script>

http-common.js

import axios from 'axios'

const API_URL = process.env.API_URL || 'http://localhost:3000/api/v1'

export const AXIOS = axios.create({
baseURL: `http://localhost:8082/Fleet-App/api/`,
withCredentials: false,
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.token,
'Access-Control-Allow-Origin': '*',
'Accept' : 'application/json, text/plain, */*',
'Access-Control-Allow-Methods' : 'GET, PUT, POST, DELETE, OPTIONS',
'Access-Control-Allow-Credentials' : true
}
})

提前致谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com