Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MiniprogramTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢卓城
MiniprogramTemplate
Commits
3d6f8597
Commit
3d6f8597
authored
Jan 20, 2021
by
谢卓城
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add request demo
parent
6496fc47
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
20 deletions
+17
-20
README.md
README.md
+2
-2
app.js
src/app.js
+2
-0
index.js
src/pages/index/index.js
+13
-18
No files found.
README.md
View file @
3d6f8597
...
...
@@ -12,8 +12,8 @@
```
npm run page <#name#> 创建名为<#name#>的page文件(文件与<#name#>同名)
npm run page:i <#name#> 创建名为<#name#>的page文件(文件都为index.*)
npm run c
omponent <#name#>
创建名为<#name#>的component文件(文件与<#name#>同名)
npm run c
omponent:i <#name#>
创建名为<#name#>的component文件(文件都为index.*)
npm run c
t <#name#>
创建名为<#name#>的component文件(文件与<#name#>同名)
npm run c
t:i <#name#>
创建名为<#name#>的component文件(文件都为index.*)
npm run build:ci 生成miniprogram_npm文件
npm run dev 开启小程序实时转码服务
...
...
src/app.js
View file @
3d6f8597
//app.js
const
Request
=
require
(
"./utils/request.js"
);
App
({
onLaunch
:
function
()
{
// 初始化axios
...
...
src/pages/index/index.js
View file @
3d6f8597
//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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment