vue解决跨域问题
1、什么是跨域
跨域问题的出现是因为浏览器的同源策略问题,同源是指 两个页面具有相同的 协议+主机+端口号,它是浏览器最核心也是最基本的功能。如果没有同源策略浏览器将会十分的不安全。
2、如何解决跨域问题
1)使用jsonp
2)使用jquery ajax
3)在vue开发中实现跨域,通过在devServer中配置 proxy
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true,
productionSourceMap: false, // 生产环境下开启 sourceMap,用于 fundebug 调试
devServer: {
open: true,
host: 'localhost',
port: 8080,
proxy: {
'/business': {
target: 'http://36.***.***.***:8888',
secure: false,
ws: true,
changeOrigin: true, //允许跨域
logLevel: 'debug',
pathRewrite: {
// '^/business': ''
}
}
}
}
})
4)cors,后端配置 Access-Control-Allow-Origin

浙公网安备 33010602011771号