view
// logs.wxml
<view class="section">
<view class="section__title">flex-direction: rowview>
<view class="flex-wrp" style="flex-direction:row;">
<view class="flex-item bc_green">1view>
<view class="flex-item bc_red" hover-class="bc_yellow">2view>
<view class="flex-item bc_blue">3view>
view>
view>
<view class="section">
<view class="section__title">flex-direction: columnview>
<view class="flex-wrp" style="height: 300px;flex-direction:column;">
<view class="flex-item bc_green" hover-class="bc_orange">1view>
<view class="flex-item bc_red">2view>
<view class="flex-item bc_blue">3view>
view>
view>
// logs.wxss
.flex-wrp{
display: flex;
}
.flex-item{
flex: 1;
width: 100rpx;
height: 100rpx;
}
.bc_green{
background-color: green;
}
.bc_red{
background-color: red;
}
.bc_blue{
background-color: blue;
}
.bc_orange{
background-color: orange;
}
.bc_yellow{
background-color: yellow;
}
// 如果需要滚动视图。需要使用 scroll-view
使用竖向滚动时,需要给一个固定高度,通过 WXSS 设置 height。
注意:
- 请勿在 scroll-view 中使用 textarea、map、canvas、video 组件
- scroll-into-view 的优先级高于 scroll-top
- 在滚动 scroll-view 时会阻止页面回弹,所以在 scroll-view 中滚动,是无法触发 onPullDownRefresh
- 若要使用下拉刷新,请使用页面的滚动,而不是 scroll-view ,这样也能通过点击顶部状态栏回到页面顶部
swiper: 滑块视图容器,swiper中只可放置swiper-item组件,swiper-item只可放置在swiper中
// item.wxml
"{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
for="{{imgUrls}}">
item>
"{{item}}" class="slide-image" width="355" height="150" />
item>
"intervalChange" show-value min="500" max="2000" /> interval
"durationChange" show-value min="1000" max="10000" /> duration
// item.js
Page({
data: {
imgUrls: [
'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
],
indicatorDots: false,
autoplay: false,
interval: 500,
duration: 100
},
changeIndicatorDots: function (e) {
this.setData({
indicatorDots: !this.data.indicatorDots
})
},
changeAutoplay: function (e) {
this.setData({
autoplay: !this.data.autoplay
})
},
intervalChange: function (e) {
this.setData({
interval: e.detail.value
})
},
durationChange: function (e) {
this.setData({
duration: e.detail.value
})
}
})
movable-area: movable-view 的可移动区域
// item.wxml
<view class="section">
<view class="section__title">movable-view区域小于movable-areaview>
<movable-area style="height: 200px;width: 200px;background: red;">
<movable-view style="height: 50px; width: 50px; background: blue;" x="{{x}}" y="{{y}}">movable-view>
movable-area>
<view class="btn-area">
<button size="mini" bindtap="tap">click me to move to (30px, 30px)button>
view>
<view class="section__title">movable-view区域大于movable-areaview>
<movable-area style="height: 100px;width: 100px;background: red;">
<movable-view style="height: 200px; width: 200px; background: blue;">movable-view>
movable-area>
view>
// item.js
Page({
data: {
x: 0,
y: 0
},
tap: function (e) {
this.setData({
x: 30,
y: 30
});
}
})
icon: 图标
// item.wxml
<view class="group">
<block wx:for="{{iconSize}}">
<icon type="success" size="{{item}}"/>
block>
view>
<view class="group">
<block wx:for="{{iconType}}">
<icon type="{{item}}" size="40"/>
block>
view>
<view class="group">
<block wx:for="{{iconColor}}">
<icon type="success" size="40" color="{{item}}"/>
block>
view>
// item.js
Page({
data: {
iconSize: [20, 30, 40, 50, 60, 70],
iconColor: [
'red', 'orange', 'yellow', 'green', 'rgb(0,255,255)', 'blue', 'purple'
],
iconType: [
'success', 'success_no_circle', 'info', 'warn', 'waiting', 'cancel', 'download', 'search', 'clear'
]
}
})
progress: 进度条
buton
// item.wxml
// item.wxss
/** 修改button默认的点击态样式类**/
.button-hover {
background-color: red;
}
/** 添加自定义button点击态样式类**/
.other-button-hover {
background-color: blue;
}
// item.js
var types = ['default', 'primary', 'warn']
var pageObject = {
data: {
defaultSize: 'default',
primarySize: 'default',
warnSize: 'default',
disabled: false,
plain: false,
loading: false
},
setDisabled: function (e) {
this.setData({
disabled: !this.data.disabled
})
},
setPlain: function (e) {
this.setData({
plain: !this.data.plain
})
},
setLoading: function (e) {
this.setData({
loading: !this.data.loading
})
}
}
for (var i = 0; i < types.length; ++i) {
(function (type) {
pageObject[type] = function (e) {
var key = type + 'Size'
var changedData = {}
changedData[key] =
this.data[key] === 'default' ? 'mini' : 'default'
this.setData(changedData)
}
})(types[i])
}
Page(pageObject)
form
// item.wxml
<form bindsubmit="formSubmit" bindreset="formReset">
<view class="section section_gap">
<view class="section__title">switchview>
<switch name="switch" />
view>
<view class="section section_gap">
<view class="section__title">sliderview>
<slider name="slider" show-value>slider>
view>
<view class="section">
<view class="section__title">inputview>
<input name="input" placeholder="please input here" />
view>
<view class="section section_gap">
<view class="section__title">radioview>
<radio-group name="radio-group">
<label>
<radio value="radio1" />radio1label>
<label>
<radio value="radio2" />radio2label>
radio-group>
view>
<view class="section section_gap">
<view class="section__title">checkboxview>
<checkbox-group name="checkbox">
<label>
<checkbox value="checkbox1" />checkbox1label>
<label>
<checkbox value="checkbox2" />checkbox2label>
checkbox-group>
view>
<view class="btn-area">
<button formType="submit">Submitbutton>
<button formType="reset">Resetbutton>
view>
form>
// item.js
Page({
formSubmit: function (e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value)
},
formReset: function () {
console.log('form发生了reset事件')
}
})
picker:从底部弹起的滚动选择器,现支持三种选择器,通过mode来区分,分别是普通选择器,时间选择器,日期选择器,默认是普通选择器。
// item.wxml
<view class="section">
<view class="section__title">地区选择器view>
<picker bindchange="bindPickerChange" value="{{index}}" range="{{array}}">
<view class="picker">
当前选择:{{array[index]}}
view>
picker>
view>
<view class="section">
<view class="section__title">时间选择器view>
<picker mode="time" value="{{time}}" start="09:01" end="21:01" bindchange="bindTimeChange">
<view class="picker">
当前选择: {{time}}
view>
picker>
view>
<view class="section">
<view class="section__title">日期选择器view>
<picker mode="date" value="{{date}}" start="2015-09-01" end="2017-09-01" bindchange="bindDateChange">
<view class="picker">
当前选择: {{date}}
view>
picker>
view>
// item.js
Page({
data: {
array: ['美国', '中国', '巴西', '日本'],
objectArray: [
{
id: 0,
name: '美国'
},
{
id: 1,
name: '中国'
},
{
id: 2,
name: '巴西'
},
{
id: 3,
name: '日本'
}
],
index: 0,
date: '2016-09-01',
time: '12:01'
},
bindPickerChange: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
index: e.detail.value
})
},
bindDateChange: function(e) {
this.setData({
date: e.detail.value
})
},
bindTimeChange: function(e) {
this.setData({
time: e.detail.value
})
}
})
picker-view: 嵌入页面的滚动选择器
// item.wxml
<view>
<view>{{year}}年{{month}}月{{day}}日view>
<picker-view indicator-style="height: 50px;" style="width: 100%; height: 300px;" value="{{value}}" bindchange="bindChange">
<picker-view-column>
<view wx:for="{{years}}" style="line-height: 50px">{{item}}年view>
picker-view-column>
<picker-view-column>
<view wx:for="{{months}}" style="line-height: 50px">{{item}}月view>
picker-view-column>
<picker-view-column>
<view wx:for="{{days}}" style="line-height: 50px">{{item}}日view>
picker-view-column>
picker-view>
view>
// item.js
const date = new Date()
const years = []
const months = []
const days = []
for (let i = 1990; i <= date.getFullYear(); i++) {
years.push(i)
}
for (let i = 1 ; i <= 12; i++) {
months.push(i)
}
for (let i = 1 ; i <= 31; i++) {
days.push(i)
}
Page({
data: {
years: years,
year: date.getFullYear(),
months: months,
month: 2,
days: days,
day: 2,
year: date.getFullYear(),
value: [9999, 1, 1],
},
bindChange: function(e) {
const val = e.detail.value
this.setData({
year: this.data.years[val[0]],
month: this.data.months[val[1]],
day: this.data.days[val[2]]
})
}
})
radio: radio-group单项选择器,内部由多个组成。
// item.wxml
"radio-group" bindchange="radioChange">
// item.js
Page({
data: {
items: [
{name: 'USA', value: '美国'},
{name: 'CHN', value: '中国', checked: 'true'},
{name: 'BRA', value: '巴西'},
{name: 'JPN', value: '日本'},
{name: 'ENG', value: '英国'},
{name: 'TUR', value: '法国'},
]
},
radioChange: function(e) {
console.log('radio发生change事件,携带value值为:', e.detail.value)
}
})
+ url(string) --- 应用内的跳转链接
+ open-type(navigate) --- 跳转方式
- navigate 对应 wx.navigateTo 的功能
- redirect 对应 wx.redirectTo 的功能
- switchTab 对应 wx.switchTab 的功能
- reLaunch 对应 wx.reLaunch 的功能
- navigateBack 对应 wx.navigateBack 的功能
+ delta(number) --- 当 open-type 为 'navigateBack' 时有效,表示回退的层数
+ hover-class(navigator-hove) --- 指定点击时的样式类,当hover-class="none"时,没有点击态效果
+ hover-start-time(50)
+ hover-stay-time(600)
video标签认宽度300px、高度225px,设置宽高需要通过wxss设置width和height。