avatar

目录
笔记-微信小程序学习

参考:【慕课网】

[TOC]

快速入门

简单介绍

开发文档:http://developers.weixin.qq.com/miniprogram/dev/api/

开发者工具:扫码登录,创建小程序项目(普通快速模版)

app.json说明

代码如下

Code
1
2
3
4
5
6
7
8
9
10
11
12
{
"pages":[
"pages/index/index",
"pages/logs/logs"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}

pages开发工具会自动在里面添加项目所有页面

开发开始

初步

新建页面:在pages目录下新建list目录,在list目录下新建page,名字叫list

更改标题:在list.json中添加

Code
1
2
3
{
"navigationBarTitleText": "区域信息列表"
}

组件介绍:

Code
1
2
3
4
5
6
view:类似于div
scroll-view:可滚动视图区域
text:文本
<text>{{text}}</text>
navigator:页面链接,相当于a
button:按钮

后台通过json与页面交互

设置:项目设置>不校验合法域名、web-view(业务域名)、TLS 版本以及 HTTPS 证书

​ 这样http://localhost:8080/sb/hello这种域名才会有效

list.wxml

html
1
2
3
<view>
<text>数据:{{msg}}</text>
</view>

list.js

javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  /**
* 生命周期函数--监听页面显示
*/
onShow: function () {
var that = this;
wx.request({
url: 'http://localhost:8080/sb/hello',
success: function (res) {
var mydata = res.data;//json的内容
console.log(mydata);
that.setData({ msg: mydata }); //给页面参数{{msg}}注入值
}
})
}
/*
- url请求返回的是json
- wx.request的content-type 默认为 'application/json'
- res.data就在控制台打印出了json串
*/
文章作者: Machine
文章链接: https://machine4869.gitee.io/2018/05/17/15326693355030/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 哑舍
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论