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

add request demo

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