Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of fetch Network request Encapsulation

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "fetch network request encapsulation example analysis", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "fetch network request encapsulation example analysis"!

Export default ({url, method = 'GET', data = null,}) = > {/ / request configuration let options = {method} / / data is not empty It is that post requests if (data) {options = {... options, body: JSON.stringify (data), headers: {'content-type':' application/json'}} return fetch (url, options). Then (res = > res.json ()). Then (data = > data)} use get

Post import fetchApi from'. / js/fetch.js' const vm = new Vue ({el:'# app', data: {users: []}, / / initiate a network request mounted () {let url = 'http://localhost:3000/api/users' / / fetchApi ({url}). Then (data = > console.log (data)) fetchApi ({url, method:' POST', data: {id: 200) Name: 'aaa'}}) .then (data = > console.log (data))}}) so far I believe that you have a deeper understanding of the "fetch network request encapsulation example analysis", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report