「小程序JAVA实战」 小程序手写属于自己的第一个demo(六)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-06/
自己尝试的写一个小demo,用到自定义样式,自定义底部导航,页面之间的跳转等小功能。
官方文档对于小程序开发来说要时刻打开https://developers.weixin.qq.com/miniprogram/dev/framework/config.html
源码:https://github.com/limingios/wxProgram.git 中的No.1
创建小程序
- 项目名称创建

- 精简下项目
>将不需要的都删除,简化成一个很简化的项目 until文件夹和logs文件夹都删除
//app.js
App({
onLaunch: function () {
}
})
//app.json
{
"pages":[
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarTextStyle":"black"
}
}

- 定义文件夹+自定义页面内容
* 复制index文件夹为idig88,将文件夹内保留idig88.js 和idig88.wxml
* 精简idig88.wxml内容
* 新增的idig88.wxml添加到app.json中,并添加到第一行让起第一个启动
* console 可能会报错,先不用管,后面咱们会解决的,第一个主要先能出效果
* 了解小程序构成结构
<!--idig88.wxml-->
<view class="container">
这是第一个demo小程序
</view>
app.json
{
"pages":[
"pages/idig88/idig88",
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "第一个demo",
"navigationBarTextStyle":"black"
}
}



- 添加底部导航栏tabBar和网络超时设置
app.json
{
"pages":[
"pages/idig88/idig88",
"pages/index/index"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "第一个demoe",
"navigationBarTextStyle":"black"
},
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"text": "首页"
},
{
"pagePath": "pages/idig88/idig88",
"text": "详情页面"
}
]
},
"networkTimeout": {
"request": 10000,
"downloadFile": 10000
},
"debug": true
}

- 修改index文件下的index.wxml和index.js了解数据绑定
- 在微信小程序,不像之前的html那种结构,这里得都是view容器的概念,要显示什么首先要通过view容器的方式。
<!--index.wxml-->
<view class="container">
<text class="user-motto">{{motto}}</text>
</view>
- 每个js都必然有Page({}) 这种结构
- data就是数据,里面有多个变量如果需要在页面显示绑定的数据{{变量名称}}
//index.js
Page({
data: {
motto: 'Hello World',
userInfo: {},
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
}
})


- index增加样式
* 新建index.wxss文件添加样式名称
* txt-test 定义局顶部的距离,在微信小程序开发建议使用rpx,这个可以做到手机端的适配
/* pages/index/index.wxss */
.txt-test{
margin-top: 800rpx;
}
- 引用css名称为txt-test的样式放入text容器内
<!--index.wxml-->
<view class="container">
<text class="txt-test">{{motto}}</text>
</view>
注意这个txt-test 就是私有的,index.wxml就是私有的html调用私有的样式文件,也可以看到container他这个样式就是在私有文件里面没有而在最外层的app.wxss,它就去父节点最外层找,如果最外层有用,没有也不报错。

「小程序JAVA实战」 小程序手写属于自己的第一个demo(六)的更多相关文章
- 「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/ 之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧.源码:ht ...
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
- 「小程序JAVA实战」小程序视频封面处理(48)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...
随机推荐
- Oracle11g数据库监听配置
(转自:http://blog.sina.com.cn/s/blog_6908928501018057.html) 经验告诉我:最好把数据库的SID和数据库全局名称分开,免得配置时混了,如果要配置服务 ...
- Database项目中关于Procedure sp_refreshsqlmodule_internal的错误
最近项目中发现一怪问题,使用DB项目发布数据库时,总提示 “(110,1): SQL72014: .Net SqlClient Data Provider: Msg 1222, Level 16, S ...
- PostgreSQL copy 时提示:ERROR: invalid byte sequence for encoding "UTF8": 0xb3
测试时使用三种文件格式: ISO-8859 Netpbm PBM image ASCII if [ $(file $filename|grep -c "ISO-8859") -gt ...
- 使用sessionStorage实现页面间传值与传对象
问题描述:业务从A页面跳转到B页面,需要由A页面向B页面传入一个对象.B页面解析对象中的值,然后根据这些值做具体的业务逻辑. 一般的传值方法如下: A页面跳转到B页面时: b.html?xxx=xxx ...
- requestAnimationFrame 与 cancelAnimationFrame
API接口 Window对象定义了以下两个接口: partial interface Window { long requestAnimationFrame(FrameRequestCallback ...
- 基于Photon 的 PUN+ 如何自动实现RPC呼叫的.
基于Photon 的 PUN+ 如何自动实现RPC呼叫的. 简单说函数标记成 RPC 类型的. void Hello() { Debug.Log("Hello"); PhotonV ...
- Solr初步使用
参考此文:https://blog.csdn.net/frankcheng5143/article/details/71159936
- Go开发Struct转换成map两种方式比较
最近做Go开发的时候接触到了一个新的orm第三方框架gorose,在使用的过程中,发现没有类似beego进行直接对struct结构进行操作的方法,有部分API是通过map进行数据库相关操作,那么就需要 ...
- (三)canvas绘制样式
beginPath() 对画线点的一个开始限制 moveTo() 画线的起点,只在开头使用 参数两个x轴,y轴 lineTo() 后续连线 两个参数x轴,y轴 stroke() 连线无填充 fill( ...
- 瀑布流下滑 发送ajax
<!DOCTYPE=html> <html> <head> <meta charset="UTF-8"> ...