第一个uni-app程序

创建项目

ctrl+R在微信模拟器运行

创建页面

右键pages,新建页面

urequest 请求api

1
2
3
4
5
6
7
8
9
10
11
12
13
uni.request({
url: 'https://unidemo.dcloud.net.cn/api/news/36kr/'+e.newsid,
method: 'GET',
data: {},
success: res => {
console.log(res);
this.title = res.data.title;
this.strings=res.data.content;
},
fail: () => {},
complete: () => {}
});

pages/info/info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<template>
<view type="content">
<view class="title">{{title}}</view>
<view class="art-content">
<rich-text class="richText" :nodes="strings"></rich-text>
</view>
</view>
</template>

<script>
export default {
data() {
return {
title:'',
strings:''
}
},
onLoad(e) {
console.log(e);
uni.request({
url: 'https://unidemo.dcloud.net.cn/api/news/36kr/'+e.newsid,
method: 'GET',
data: {},
success: res => {
console.log(res);
this.title = res.data.title;
this.strings=res.data.content;
},
fail: () => {},
complete: () => {}
});
},
methods: {

}
}
</script>

<style>
/*.content{pending:10upx;width 96%;flex-wrap:wrap;}
//.title{line-height: 2em;font-weight:700;font-size: 38upx;}*/
</style>