和picker组件不同,picker-view组件可以嵌入页面,不通过单击弹出
picker-view由两部分组成
- 一个是外层的
- 一个是嵌入其中的
picker-view组件的属性
pick-view组件的使用示例
index.wxml
---------------------------
<view>
<view>你选择的是:{{value}}区</view>
<picker-view
indicator-style="height: 50px;"
style="width: 100%; height: 300px;"
value="{{value}}"
bindchange="bindChange"
>
<picker-view-column>
<view wx:for="{{region}}" style="line-height: 50px">{{item}}区</view>
</picker-view-column>
</picker-view>
</view>
-----------------------------------------------------------------------------------
index.js
--------------
Page({
data: {
value:"海淀",
region:[
"海淀","朝阳","东城","西城","昌平","丰台","大兴","房山","门头沟","石景山","顺义","延庆
","怀柔","密云","通州"
]
},
bindChange(e) {
console.log(e)
const val = e.detail.value
var value = this.data.region[val];
this.setData({
value: value
})
}
})