vue请求strict-origin-when-cross-origin 处理
"strict-origin-when-cross-origin" 是浏览器的一个安全策略,用于处理跨域请求。当使用该策略时,浏览器会在同源请求时发送完整的 Referer 头部信息,但在跨域请求时则会发送相对路径的 Referer 头部信息。
如果你想要在 Vue 中处理跨域请求,并且希望发送完整的 Referer 头部信息,可以按照以下步骤进行操作:
- 在
vue.config.js文件中添加以下配置:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://api.example.com', // 设置你想要请求的目标 URL
changeOrigin: true,
headers: {
Referer: 'http://your-origin.com' // 设置你想要发送的 Referer 头部信息
}
}
}
}
}
在上述配置中,/api 是你想要发送请求的路径前缀,http://api.example.com 是你想要请求的目标 URL,http://your-origin.com 是你想要发送的 Referer 头部信息。
- 在 Vue 组件中使用 Axios 或其他 HTTP 请求库发送请求:
import axios from 'axios'
axios.get('/api/data').then(response => {
console.log(response.data)
}).catch(error => {
console.error(error)
})
在上述代码中,/api/data 是你想要请求的具体路径。
通过以上配置和代码,你就可以在 Vue 中处理跨域请求,并且发送完整的 Referer 头部信息。请注意,这只是一种处理方法,具体的实现方式可能因你的项目结构和需求而有所不同
AI 优化版
原文地址:https://www.cveoy.top/t/topic/hJ0t 著作权归作者所有。请勿转载和采集!