当前位置:网站首页>[step on the pit series] H5 cross domain problem of uniapp
[step on the pit series] H5 cross domain problem of uniapp
2022-07-07 08:08:00 【The sea of waves】
List of articles
【 Step on the pit series 】uniapp And h5 Cross domain issues
Preface
Debug the mobile interface on the browser , appear Multiple... Are not allowed ‘Access-Control-Allow-Origin’ CORS Header information . And see Response Information returned , It is thought that there are many configurations on the server Settings for cross domain access , The problem caused by , So I've been looking for problems on the back end , After spending some time checking , Multiple cross domain access settings are not configured , And the real machine of the mobile terminal can be accessed normally , This has reversed the idea of investigation , Solve the problem from the front end .
What is cross-domain
Cross domain is a browser specific concept , finger js The code accesses sites other than its own source site . such as A In the web page of the site js Code , Request the B Site data , It's cross domain .
A and B To be considered a homogeneous domain , Then there must be the same agreement ( such as http and https No way. )、 Same domain name 、 And the same port number (port).
If you are doing App、 Small program, etc H5 platform , It does not involve cross domain issues .
How to solve
Solution :uni-app The official recommendation Use HBuilderX Browser built in
Go preview , There will be no cross domain issues in built-in browsers ; But if it is Chrome This cross domain problem will appear when previewing in browser , Official recommendation install Allow-Control-Allow-Origin: * plug-in unit
The way to solve . Reference resources :uni-app H5 Cross domain problem solution (CORS、Cross-Origin).
# Whether cross domain access is allowed CORS, If allowed , Set allowed domain names
accessControlAllowOrigin: '*'
# When cross domain access is allowed CORS, Methods and request headers that can be retrieved and returned
accessControlAllowMethods: GET, POST, OPTIONS
accessControlAllowHeaders: content-type, x-requested-with, x-ajax, x-token, x-remember
accessControlExposeHeaders: x-remember
Reference article
uni-app H5 Cross domain problem solution (CORS、Cross-Origin)
边栏推荐
- 复杂网络建模(三)
- Summary of redis functions
- Blob 對象介紹
- ZCMU--1492: Problem D(C语言)
- 【数字IC验证快速入门】14、SystemVerilog学习之基本语法1(数组、队列、结构体、枚举、字符串...内含实践练习)
- ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
- Cnopendata American Golden Globe Award winning data
- Niu Mei's mathematical problem --- combinatorial number
- 复杂网络建模(二)
- LeetCode简单题之判断一个数的数字计数是否等于数位的值
猜你喜欢
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Ansible
【数字IC验证快速入门】11、Verilog TestBench(VTB)入门
Qt学习27 应用程序中的主窗口
The charm of SQL optimization! From 30248s to 0.001s
2022 recurrent training question bank and answers of refrigeration and air conditioning equipment operation
Ansible
2022茶艺师(初级)考试题模拟考试题库及在线模拟考试
Cnopendata list data of Chinese colleges and Universities
电池、电机技术受到很大关注,反而电控技术却很少被提及?
随机推荐
Main window in QT learning 27 application
运放电路的反馈电阻上并联一个电容是什么作用
ZCMU--1492: Problem D(C语言)
JS cross browser parsing XML application
C language communication travel card background system
Linux Installation MySQL 8.0 configuration
Blob 对象介绍
Li Kou interview question 04.01 Path between nodes
2022年茶艺师(中级)考试试题及模拟考试
微信小程序基本组件使用介绍
Thinkcmf6.0 installation tutorial
Most elements
青龙面板-今日头条
Find the mode in the binary search tree (use medium order traversal as an ordered array)
复杂网络建模(三)
Linux server development, MySQL cache strategy
Es FAQ summary
Complex network modeling (I)
[quick start of Digital IC Verification] 17. Basic grammar of SystemVerilog learning 4 (randomization)
Leetcode 40: combined sum II