小程序结构javascript
渲染层:WXML + WXSS(相似于HTML CSS)
逻辑层:JavaScript
配置:JSONvue
======最基本的文件结构======
pages->
test->
test.js
test.wxml
test.wxss
test.json
app.json
app.js
app.wxss
project.config.jsonjava
==========配置导航===============
在pages下的json文件里配置,根据开发文档来配置web
=======元素===========
<text></text> 相似span标签
<image></image> 相似img 绝对路径:"/images/01.png"
<view></view> 相似divjson
=====响应式长度单位rpx========
让元素适配不一样的屏幕宽度
不管哪一种设备,都规定屏幕宽度为750rpx小程序
========导航组件navigator==========
相似a标签
属性
url 用来跳转page url="/pages/weekly/weekly"
open-type 跳转后可否返回
redirect 不能返回
navigate 能返回
switchTab 有tabBar时使用,能够跳转对应页,tab也有相应的反馈(变色)
hover-class 按住时显示的样式,后面直接加class名称,样式必须在正常样式以后定义,不然失效架构
=======tabBar=============
选项卡
在app.json里app
"list": [ { "pagePath": "pages/about/about", "text": "关于", //显示的文字 "iconPath": "images/icons/home1.png", //未选中时的iconfont "selectedIconPath": "images/icons/home2.png" //选中时的iconfont }, { "pagePath": "pages/weekly/weekly", "text": "每周推荐", "iconPath": "images/icons/neirong1.png", "selectedIconPath": "images/icons/neirong2.png" } ], "color":"#000", //平时字体的颜色 "selectedColor":"#00f" //选中时字体的颜色 },
=====选项卡统一导航样式=======
在app.json里xss
"window": { "navigationBarBackgroundColor": "#fff", "navigationBarTextStyle": "black" }
======数据绑定==========
与vue相似,在对应的js的data里赋值,而后{{msg}}调用
也能够用表达式{{(score>=60?"及格":"不及格")}}字体
=====小程序运行环境与基本架构====
运行环境(宿主环境) 能够调用本机的一些接口
视图层(渲染层)和逻辑层
各自描述语言
各自的运行进程
(about页和weekly页,都内置了一个webviewId的内部状态变量,来记录他们各自是在记好webiew进程之中进行渲染)
二者基于数据绑定和事件机制的通信(逻辑层对数据进行处理后,发送给视图层,视图层根据发送的内容对对应的部分渲染
=======wx:if===========
相似v-show,当为true的时候显示
<text wx:if="{{list.isHighlyRecommended}}">强烈推荐</text>
=======wx:for==========
相似v-for,可是他用的是item,下标是index
<view class="list clearfix" wx:for="{{list}}"> <image class="list-image" src="{{item.imagePath}}"></image> <view class="list-details"> <text>第{{index+1}}周:{{item.name}}</text> <text>{{item.comment}}</text> </view> </view>
========swiper轮播===========
默认高度是150rpx
swiper-item里能放各类内容
indicator-dots 显示控制点
--前一页与后一页都露出一点--
previous-margin="50rpx"
next-margin="50rpx"
<swiper style="background:#eee" indicator-dots='{{true}}'> <swiper-item>123</swiper-item> <swiper-item>456</swiper-item> <swiper-item>789</swiper-item> </swiper>