Commit 3d6f8597 authored by 谢卓城's avatar 谢卓城

add request demo

parent 6496fc47
......@@ -12,8 +12,8 @@
```
npm run page <#name#> 创建名为<#name#>的page文件(文件与<#name#>同名)
npm run page:i <#name#> 创建名为<#name#>的page文件(文件都为index.*)
npm run component <#name#> 创建名为<#name#>的component文件(文件与<#name#>同名)
npm run component:i <#name#> 创建名为<#name#>的component文件(文件都为index.*)
npm run ct <#name#> 创建名为<#name#>的component文件(文件与<#name#>同名)
npm run ct:i <#name#> 创建名为<#name#>的component文件(文件都为index.*)
npm run build:ci 生成miniprogram_npm文件
npm run dev 开启小程序实时转码服务
......
//app.js
const Request = require("./utils/request.js");
App({
onLaunch: function() {
// 初始化axios
......
//index.js
//获取应用实例
const app = getApp();
const { getHomeList } = require("../../apis/root.js");
Page({
data: {
......@@ -11,15 +10,13 @@ Page({
//事件处理函数
bindViewTap: function() {
// 网络请求
app._get(
"page/home",
res => {
getHomeList()
.then(res => {
console.log("发起get请求-res", res);
},
err => {
console.log("发起get请求-err", err);
}
);
})
.catch(err => {
console.log("请求失败!" + err);
});
},
onLoad: function() {
if (app.globalData.userInfo) {
......@@ -51,15 +48,13 @@ Page({
},
requestAction(e) {
// 网络请求
app._get(
"",
res => {
getHomeList()
.then(res => {
console.log("发起get请求-res", res);
},
err => {
console.log("发起get请求-err", err);
}
);
})
.catch(err => {
console.log("请求失败!" + err);
});
},
getUserInfo: function(e) {
console.log(e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment