当前位置:网站首页>Network module packaging
Network module packaging
2022-06-23 01:28:00 【The opening of a midsummer night】
Network module encapsulation
Select what network module :
vue There are many ways to send network requests in , that , In development , How to choose ? Choose one : Conventional Ajax Is based on XMLHttpRequestKXHR)
Why not use it ?
Very easy to explain , Configuration and calling methods are very confusing .
It's very painful to code .
So it's rarely used directly in real development , But use jQuery-Ajax
Choice two : In the previous study , We often use jQuery-Ajax
Compared with the traditional Ajax Very easy to use .
Why not choose it ?
First , Let's be clear : stay Vue It's not necessary in the whole development of
Use jQuery 了 .
that , It means that in order to facilitate us to make a network request , To quote a jQuery, Do you think it's reasonable ?
jQuery Code for 1w+ That's ok .
Vue Code for 1w+ That's ok .
There's no need to refer to this heavyweight framework for network requests .
Choose three : The official in the Vue1.x When , Launched Vue-resource.Vue-resource The volume of is relative to jQuery Many small .≥ in addition Vue-resource It's official .
Why not choose it ?
stay Vue2.0 after , Vue The author is in GitHub Of Issues Description in
Removed vue-resource, And it won't be updated in the future .
So it means later vue-reource When a new version is no longer supported , either
Will continue to update and maintain .
There are great hidden dangers in the future project development and maintenance .
Option 4 : In the statement no longer continue to update and maintain vue-resource At the same time , The author also recommends a framework : axios Why not use it ?
axios There are many advantages , And it's very convenient to use .> later , We studied him in detail .
jsonp
In front end development , One of our common network requests is JSONP, Use JSONP The main reason is often to solve the problem of cross domain access .
JSONP What is the principle of ?
JSONP At the heart of it is through <script> Labeled src To help us request data . The reason is that our project is deployed in domain1.com On the server , You can't directly access domain2.com Data on the server .
At this time, we use <script> Labeled src Help us go to the server to request data , Think of data as a javascript To perform , And in the process of execution, we pass in what we need json.
So package jsonp The core of this is that we monitor window Upper jsonp The name of the callback .
JSONP encapsulation
Let's encapsulate a process together JSONP The code of .


axiox Request mode
Support multiple request methods :
- axios(config)
- axios.request(config)
- axios.get(url[, config])
- axios.delete(url[, config])
- axios.head(url[, config])
- axios.post(url[, data[, configl])
- axios.put(url[, data[, config]])
- axios.patch(url[, data[, config]])
axiox Basic use of framework :
边栏推荐
- Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe
- leetcode 91. Decode Ways 解码方法(中等)
- SAP ui5 application development tutorial 102 - detailed explanation of the print function of SAP ui5 applications
- Pat class A - 1014 waiting in line (bank queuing problem | queue+ simulation)
- Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times
- LINQ query
- HDU - 7072 double ended queue + opposite top
- 3D printing microstructure
- 層次選擇器
- Explain the startup process of opengauss multithreading architecture in detail
猜你喜欢

Autumn move script B

Tidb monitoring upgrade: a long way to solve panic
![Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;](/img/75/d2ad171d49611a6578faf2d390af29.jpg)
Found several packages [runtime, main] in ‘/usr/local/Cellar/go/1.18/libexec/src/runtime;

Yyds dry inventory solution sword finger offer: print the binary tree into multiple lines

Lexical Sign Sequence

07 project cost management
![[launch] redis Series 2: data persistence to improve availability](/img/f4/5bc7ca3e17c6656e71df515182842e.png)
[launch] redis Series 2: data persistence to improve availability

Local deployment and problem solving of IIS in ArcGIS JS 4.23

Read Amazon memorydb database based on redis

How to refine permissions to buttons?
随机推荐
时间复杂度
The road of architects starts from "storage selection"
Flink synchronizes MySQL data to es
Day500: keyboard line
Sélecteur de hiérarchie
崔鹏团队:万字长文梳理「稳定学习」全景图
Vector 2 (friend and copy construction)
three. JS simulated driving tour art exhibition hall - creating super camera controller
3D printing microstructure
Explain the startup process of opengauss multithreading architecture in detail
Webdriver and selenium Usage Summary
JMeter associated login 302 type interface
Pat a - 1010 radical (thinking + two points)
How to calculate the position of gold ETF
"Hearing" marketing value highlights, Himalaya ushers in a new situation
What aspects of language and database knowledge are needed to build a web Kanban!
A hundred lines of code to realize reliable delay queue based on redis
C#.NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)
Pat class A - 1007 maximum subsequence sum
C#. Net universal database access encapsulation classes (access, sqlserver, Oracle)