Vue学习记录之二十六 Vue3中跨域

Vue3 (Proxy代理解决跨域) vue3中使用proxy代理机制解决跨域问题。 阅读详情

跨域(Cross-Origin)指的是浏览器的同源策略(Same-Origin Policy)限制了一个源(域、协议和端口)下的 JavaScript 脚本访问另一个源的资源。为了保护用户数据的安全,浏览器默认禁止网页向其他域发送请求或访问资源,这种限制称为跨域限制。

1. 同源策略

同源策略要求以下三者相同才算同源:

  • 协议:如 http 和 https
  • 域名:如 example.com
  • 端口:如 :80 和 :443

例如:

  • http://example.com 和 https://example.com 是跨域的(协议不同)。
  • http://example.com 和 http://sub.example.com 是跨域的(域名不同)。
  • http://example.com:80 和 http://example.com:8080 是跨域的(端口不同)。

2. 常见的跨域场景

  • API 请求:前端应用需要向不同的 API 域名请求数据,例如从 http://localhost:3000 请求 http://api.example.com。
  • CDN 资源加载:网站从其他域名的 CDN 加载静态资源。
  • 嵌套页面:通过 <iframe> 加载不同源的网页内容。

3. 解决跨域问题的方法

(1)CORS(跨域资源共享)

W3C标准,服务器可以通过设置 Access-Control-Allow-Origin 头部来允许跨域请求。CORS 是目前最主流的跨域解决方案,允许服务器设置哪些域可以访问其资源。IE不能低于IE10。主要用于服务端的配置。需要浏览器和服务器端同时支持。
可以使用中间件:cors

示例:

Access-Control-Allow-Origin: http://example.com
//或者
"Access-Control-Allow-Origin": "*"   //使用通配符,任何地址都可以访问,但安全性不高。

实例:
建立一个新的文件夹,使用 npm init 生成 package.json, 安装依赖

pnpm install koa -D   #koa模块
pnpm install koa-router -D # 路由模块
pnpm install koa2-cors -D  # 中间件模块
npm install -g nodemon #是一个实用程序,它监视 Node.js 应用程序中的文件变化,并在检测到变化时自动重新启动应用程序。它非常适合开发环境,因为它节省了手动重启服务器的时间和精力。 热启动

app.js

/*
1、http: Node.js 的核心模块,提供基本的 HTTP 功能,如创建服务器、处理请求和响应。它较为底层,使用时需要手动处理很多细节。
2、Express: 基于 http 的框架,简化了 HTTP 服务器的构建。它提供了更高层的 API,使路由、请求处理和中间件的使用更加便捷。适合快速开发 RESTful API 和 web 应用。
3、Koa: 由 Express 的创建者开发,是一个更轻量级且现代化的框架。Koa 使用 async/await 语法,允许更优雅的错误处理和中间件链管理。它的设计目标是更小、更强大、可扩展性更高。
*/
const Koa = require('koa')
const cors = require('koa2-cors')  //中间件
const app = new Koa()

const index = require('./router/index')
//实际开发中会配置域名白名单,只允许这些域名发起请求。
app.use(cors({
   
   
    origin: '*', // 相当于Access-Control-Allow-Origin:允许所有源,或者你可以指定特定的源如 'http://example.com'
    allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
    allowHeaders: ['Content-Type', 'Authorization', 'Accept'],
}))
//将路由注册到应用。
app.use(index.routes(), index.allowedMethods(
【Vue】项目:尚品汇后台管理系统(下) 记录尚品汇后台管理系统的开发过程,功能模块包括登录、首页、品牌管理、平台属性管理、SKU管理、SPU管理、用户管理、角色管理、菜单管理模块。后台管理系统是CMS内容管理系统的一个子集,通过项目实战可以彻底搞明白菜单权限、按钮权限如何实现,掌握市场中数据可视化ECharts、V-charts的运用。... 阅读详情

相关推荐

vue3配置跨域

【代码】vue3配置跨域。

weixin_42066070的博客 1577

二十六、【健壮性与审计篇】操作日志:前端日志管理界面的设计与实现

本文介绍了操作日志系统的设计与实现,分为后端与前端两部分。后端部分包括创建OperationLog模型存储日志数据,利用工具函数记录关键操作,并提供API接口;前端部分则实现日志管理界面,支持筛选和分页功能。

blues_C的博客 1099

AI驱动视频剪辑自动化:cutcli命令行工具重塑工作流

视频剪辑自动化是提升内容生产效率的关键技术,其核心原理在于通过程序化指令替代手动操作,将创意执行过程代码化。这项技术的价值在于能够将创作者从重复性劳动中解放,实现批量化、标准化的视频内容生产,尤其适用于社交媒体运营、产品宣传等高频产出场景。通过封装专业软件(如剪映/CapCut)的底层草稿格式,自动化工具在保证工业级渲染质量的同时,提供了可编辑的中间态,为AI智能体(Agent)与生产工具的结合提供了清晰接口。本文以cutcli为例,深入探讨了如何通过命令行工具和AI助手,构建从自然语言指令到可编辑视频草稿

weixin_27210125的博客 1083

大疆sdkV4以及V5webrtc推流

webrtcSDK中要用它的VideoCapturer来初始化推流 ViewdoCapturer是一个接口我们继承它 然后重建创建文件CapturerAircraft.java文件。CameraUtil.java这个是我们用来创建CapturerAircraft的一个工具。除了CapturerAircraft这个文件不一样外其他都是一样的。PlayBodyBean.java这个是我们的配置文件。下面的有个代码块第一个是v4的 第二个是v5的。接着我们来创建几个推流用到的webrtc工具。

weixin_41624865的博客 1190

银河麒麟V10系统下VLC播放器安装全攻略(附3.0.9.2版本离线包下载)

本文详细介绍了在银河麒麟V10操作系统无网络环境下,从零开始编译安装VLC 3.0.9.2播放器的完整攻略。通过构建本地YUM仓库解决依赖问题,提供离线资源包下载,并逐步指导完成编译环境配置、软件编译与安装,帮助用户在国产麒麟系统上成功部署强大的多媒体播放能力。

a2b3c4d5e的博客 1277

扫地机器人:从仿真到决策,一个完整SLAM导航系统的自研之路

本文详细记录了从零开始自研扫地机器人SLAM导航系统的全过程,涵盖ROS-Gazebo仿真系统搭建、地图预处理优化、全覆盖规划算法迭代等关键技术。通过三次算法升级,最终实现92%的清洁效率,并分享DWA调参、状态机设计等实战经验,为开发者提供从仿真到落地的完整解决方案。

weixin_29053695的博客 360

小白快速上手 labelimg:新手图像标注详解教程

本教程主要帮助没有使用过labelimg的小白上手该软件,快速学会基本操作和打标签,为数据集准备打下基础。

小白一枚~ 2万+

Autosar 下电过程-基于ETAS工具

本文介绍基于ETAS工具对应的BIP包的下电过程,仅供参考。在最后调用SBC下电时,需要理清楚SBC的休眠流程,否则可能会出现休眠又唤醒情况。后面有空会介绍9471的休眠流程。

赞的博客 823

ICC2: 如何让CTS指定pin多长指定长度

这里create_clock不需要写到sdc里,在脚本里写就行,需要注意的是脚本里存在remove_clock_tree的话,add_buffer就要放remove_clock_tree后面,或者给guide buffer设don't touch也行。跟innovus的操作逻辑一样,如果要让tree上的某一点长长,要先考虑这个点后面的clock tree能正常balance。我正在「拾陆楼」和朋友们讨论有趣的话题,你⼀起来吧?-5意味着长长5ns,相反正值意味着做短。

m0_61544122的博客 700

python批量调用大模型API:多线程和异步协程

本文介绍了利用多线程技术批量调用大模型API的实现方法。核心是通过并发请求提高处理效率,主要采用线程池管理并发数量、结果聚合等技术。文章提供了一个完整的Python实现示例,包含APIBatchCaller类及其single_api_call和batch_call方法,详细解析了并发控制、错误处理等关键点,并给出了使用注意事项,包括并发数设置、重试策略和超时处理等。该方案特别适合IO密集型任务,能显著提升批量API调用的效率。

Cachel Wood的博客 763

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

上一篇: Vue学习记录之二十五 Vue3中Web Componets的使用
下一篇: Vue学习记录之二十七 Pinia的使用
LvManBa
博客等级 码龄14年 650粉丝 68原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值