扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

UniApp涓璾ni.request鏂规硶鎬庝箞浣跨敤

扬州沐宇科技
2023-12-23 01:28:13
uniapp

瑕佸湪UniApp涓娇鐢╱ni.request鏂规硶锛岄渶瑕佸厛寮曞叆uni瀵硅薄銆?/p>

  1. 寮曞叆uni瀵硅薄
import uni from 'uni-app';
  1. 浣跨敤uni.request鏂规硶鍙戦€佽姹?/li>
uni.request({
  url: 'http://example.com/api',
  method: 'GET',
  data: {
    key1: 'value1',
    key2: 'value2'
  },
  header: {
    'content-type': 'application/json'
  },
  success: (res) => {
    console.log(res.data);
  },
  fail: (err) => {
    console.log(err);
  }
});

鍦ㄤ笂闈㈢殑绀轰緥涓紝鎴戜滑浣跨敤浜唘ni.request鏂规硶鍙戦€佷簡涓€涓狦ET璇锋眰锛岃姹傜殑URL鏄€檋ttp://example.com/api鈥欙紝璇锋眰鍙傛暟鏄痥ey1=value1鍜宬ey2=value2銆傚湪鎴愬姛鍥炶皟鍑芥暟涓紝鎴戜滑鎵撳嵃浜嗚繑鍥炵殑鏁版嵁锛涘湪澶辫触鍥炶皟鍑芥暟涓紝鎴戜滑鎵撳嵃浜嗛敊璇俊鎭€?/p>

浣犲彲浠ユ牴鎹嚜宸辩殑闇€姹備慨鏀硅姹傛柟娉曘€乁RL銆佽姹傚弬鏁般€佽姹傚ご绛夈€?/p>

扫码添加客服微信