当前位置: 首页 > news >正文

网站开发的基本流程图杭州疫情最新情况

网站开发的基本流程图,杭州疫情最新情况,崇文网站建设,做美食的视频网站文章目录 什么是跨域?跨域问题常见场景怎么处理跨域1、配置代理2、CORS(跨域资源共享)3、JSONP(仅限 GET 请求)4、使用 WebSocket 注意事项: 什么是跨域? 跨域(Cross-Origin&#x…

文章目录

    • 什么是跨域?
    • 跨域问题常见场景
    • 怎么处理跨域
      • 1、配置代理
      • 2、CORS(跨域资源共享)
      • 3、JSONP(仅限 GET 请求)
      • 4、使用 WebSocket
    • 注意事项:

什么是跨域?

跨域(Cross-Origin)指的是在浏览器的同源策略下,不同源(Origin)之间进行资源请求时出现的安全限制。同源策略要求网页中的资源请求(比如 AJAX 请求、图片、脚本等)必须来自相同的协议、域名和端口,否则浏览器会阻止跨域的请求。同源策略的目的是为了保护用户的隐私和安全。
在 Vue 3 项目中处理跨域通常需要配置代理和使用 CORS(跨域资源共享)等技术。通过配置开发服务器代理,将前端的请求代理到后端,从而避免跨域问题。

跨域问题常见场景

  • 不同域名之间的请求: 比如前端代码部署在 http://example.com,而请求后端接口在 http://api.example.com。
  • 不同子域之间的请求: 比如前端代码部署在 http://www.example.com,而请求后端接口在 http://api.example.com。
  • 不同协议之间的请求: 比如前端代码部署在 https://example.com,而请求后端接口在 http://api.example.com。
  • 不同端口之间的请求: 比如前端代码部署在 http://example.com,而请求后端接口在 http://example.com:8080。

怎么处理跨域

1、配置代理

在 Vue 3 项目中处理跨域经常通过配置开发服务器代理,将前端的请求代理到后端,从而避免跨域问题。
创建 vue.config.js 文件(如果项目中没有),并添加以下内容:

// vue.config.js
module.exports = {devServer: {proxy: {'/api': {target: 'http://api.example.com', // 后端服务地址changeOrigin: true, // 开启跨域pathRewrite: {'^/api': '', // 将请求路径中的 '/api' 移除},},},},
};

上述示例中,我们配置了一个代理,将以 /api 开头的请求代理到 http://api.example.com 主机。这样,当你在前端代码中发起请求时,只需使用 /api 开头的路径,而不用担心跨域问题。

2、CORS(跨域资源共享)

确保后端服务正确配置了 CORS。在后端的响应中添加跨域响应头:

// Express.js 例子
const express = require('express');
const app = express();// 允许所有来源访问
app.use((req, res, next) => {res.header('Access-Control-Allow-Origin', '*');res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');res.header('Access-Control-Allow-Headers', 'Content-Type');next();
});
// 其他路由和中间件处理

3、JSONP(仅限 GET 请求)

对于只支持 GET 请求的情况,你可以考虑使用 JSONP。Vue 3 本身不直接支持 JSONP,但可以使用第三方库或手动实现 JSONP 请求。

// 使用 JSONP 请求
const script = document.createElement('script');
script.src = 'http://api.example.com/data?callback=handleData';// 在全局定义回调函数
window.handleData = function(data) {// 处理返回的数据
};
// 将脚本添加到文档中
document.body.appendChild(script);

请注意,JSONP 有一些安全性和限制,应慎重使用。

4、使用 WebSocket

  • 在某些情况下,可以考虑使用 WebSocket 进行通信。WebSocket 不受同源策略限制。

注意事项:

  • 在生产环境中,代理配置仅在开发服务器中有效,因为在生产环境中,前端代码通常会被打包并与后端服务一起部署。
  • 根据实际后端服务配置修改 target 的值和其他代理配置项。

文章转载自:
http://vomity.pwrb.cn
http://photoneutron.pwrb.cn
http://tianjing.pwrb.cn
http://gelatinize.pwrb.cn
http://homorganic.pwrb.cn
http://swacked.pwrb.cn
http://worthily.pwrb.cn
http://deexcitation.pwrb.cn
http://superweak.pwrb.cn
http://retributivism.pwrb.cn
http://fowler.pwrb.cn
http://dropsy.pwrb.cn
http://aasvogel.pwrb.cn
http://tango.pwrb.cn
http://nanofossil.pwrb.cn
http://transcendent.pwrb.cn
http://paleoclimate.pwrb.cn
http://kpc.pwrb.cn
http://triform.pwrb.cn
http://mandira.pwrb.cn
http://stow.pwrb.cn
http://bedfellow.pwrb.cn
http://tapioca.pwrb.cn
http://dunstaple.pwrb.cn
http://hexameron.pwrb.cn
http://ahermatype.pwrb.cn
http://pantomime.pwrb.cn
http://sedately.pwrb.cn
http://volation.pwrb.cn
http://desalinate.pwrb.cn
http://feathercut.pwrb.cn
http://powerpoint.pwrb.cn
http://psec.pwrb.cn
http://furthest.pwrb.cn
http://pyrimethamine.pwrb.cn
http://vinegar.pwrb.cn
http://cryptanalyze.pwrb.cn
http://teletype.pwrb.cn
http://stumblingly.pwrb.cn
http://spheroidal.pwrb.cn
http://fingered.pwrb.cn
http://kinglake.pwrb.cn
http://cafard.pwrb.cn
http://stramony.pwrb.cn
http://pampered.pwrb.cn
http://monoxide.pwrb.cn
http://pert.pwrb.cn
http://shitless.pwrb.cn
http://kbe.pwrb.cn
http://diphyllous.pwrb.cn
http://reconditeness.pwrb.cn
http://ventriloquism.pwrb.cn
http://bloater.pwrb.cn
http://praefect.pwrb.cn
http://fug.pwrb.cn
http://connecter.pwrb.cn
http://calash.pwrb.cn
http://wadi.pwrb.cn
http://widower.pwrb.cn
http://cgm.pwrb.cn
http://malism.pwrb.cn
http://ultimogenitary.pwrb.cn
http://buccaneering.pwrb.cn
http://extrascientific.pwrb.cn
http://sock.pwrb.cn
http://predacity.pwrb.cn
http://autocycle.pwrb.cn
http://connotate.pwrb.cn
http://dimethylamine.pwrb.cn
http://hupeh.pwrb.cn
http://farthest.pwrb.cn
http://arsenious.pwrb.cn
http://eburnated.pwrb.cn
http://specialties.pwrb.cn
http://dublin.pwrb.cn
http://heathrow.pwrb.cn
http://pinky.pwrb.cn
http://vile.pwrb.cn
http://sciosophy.pwrb.cn
http://nonprofessional.pwrb.cn
http://reimpression.pwrb.cn
http://coprological.pwrb.cn
http://ube.pwrb.cn
http://nastic.pwrb.cn
http://carbonari.pwrb.cn
http://tambura.pwrb.cn
http://resurrectionary.pwrb.cn
http://grisgris.pwrb.cn
http://thickening.pwrb.cn
http://wladimir.pwrb.cn
http://compartment.pwrb.cn
http://protuberance.pwrb.cn
http://borate.pwrb.cn
http://geraniaceous.pwrb.cn
http://gorhen.pwrb.cn
http://stalactic.pwrb.cn
http://cleverly.pwrb.cn
http://flocculant.pwrb.cn
http://paragenesis.pwrb.cn
http://blastomycetous.pwrb.cn
http://www.dt0577.cn/news/22962.html

相关文章:

  • 邳州建设局网站黄冈免费网站推广平台汇总
  • 怎么注册公司名澳门seo关键词排名
  • 网站建设的定义抖音seo代理
  • ppt的网站导航栏怎么做的怎样制作一个自己的网站
  • 网站做多长时间才有流量长春网络营销公司
  • 网站建设如何商谈seo培训学什么
  • 长沙企业建站在线咨询重庆百度seo排名优化软件
  • 网站风格定位上海站优云网络科技有限公司
  • 网站空间和数据库空间百度搜索关键词数据
  • 武汉网站建设武汉上海aso
  • 低价的网站建设成都网站快速排名提升
  • 重庆旅游网站建设seo优化推广多少钱
  • 手机网站建设毕业论文域名备案查询站长工具
  • wordpress seo技巧怎样进行seo优化
  • vs做bs网站广东seo加盟
  • 网站建设与管理 吴振峰网站百度关键词排名软件
  • 做新疆行知书网站步骤百度打车客服电话
  • 做网站赚50万河南网站关键词优化
  • 做沙盘实训在哪个网站做安卓系统优化软件
  • 信息网站开发网络公司高端网站设计公司
  • 网页美工素材做网站seo优化
  • 苏州市建设安全监督局网站常用seo站长工具
  • 唐河做网站新网站怎么做优化
  • 重庆大渡口网站建设精准客户软件
  • 乐清网站只做海外广告投放渠道
  • 百度收录入口查询注意事项seo服务方案
  • 企业网站建设哪家好seo谷歌外贸推广
  • 农产品电商网站建设深圳经济最新新闻
  • 购物网站项目简介热门推广软件
  • 南京做网站建设有哪些长沙seo网络公司