实战篇(零)
- 函数和字符串
- 调用函数使用.xxx()的方式,括号跟跟参数,可以是缺省的
- 拼接字符串使用+连接
- 函数返回值使用关键字return。
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
// let ymdArray = [year, month, day]
// let ymdStr = ymdArray.map(maggieNumber).join('/');
let yearStr = maggieNumber(year)
let monthStr = maggieNumber(month)
let dayStr = maggieNumber(day)
let ymdStr = yearStr + "/" + monthStr + "/" + dayStr
let hourStr = maggieNumber(hour)
let minuteStr = maggieNumber(minute)
let secondStr = maggieNumber(second)
let hmsStr = hourStr + ":" + minuteStr + ":" +secondStr
return ymdStr + ' ' + hmsStr
}
const maggieNumber = n => {
if (n > 9) {
return n.toString()
} else {
return '0' + n.toString()
}
// n = n.toString()
// return n[1] ? n : '0' + n
}
module.exports = {
formatTime: formatTime
}
- wxml和wxss
- 一对<></>表示一组标签,标签可以嵌套
- class是一种样式
- flex是一种布局方式,称为弹性布局
<!--logs.wxml-->
<view class="container log-list">
<block wx:for="{{logs}}" wx:for-item="log">
<text class="log-item">{{index + 1}}. {{log}}</text>
</block>
</view>
.log-list {
display: flex;
flex-direction: column;
padding: 40rpx;
}
.log-item {
margin: 10rpx;
}
网友评论