和picker组件不同,picker-view组件可以嵌入页面,不通过单击弹出

picker-view由两部分组成

  • 一个是外层的
  • 一个是嵌入其中的

picker-view组件的属性

image.pngpick-view组件的使用示例

  1. index.wxml
  2. ---------------------------
  3. <view>
  4. <view>你选择的是:{{value}}区</view>
  5. <picker-view
  6. indicator-style="height: 50px;"
  7. style="width: 100%; height: 300px;"
  8. value="{{value}}"
  9. bindchange="bindChange"
  10. >
  11. <picker-view-column>
  12. <view wx:for="{{region}}" style="line-height: 50px">{{item}}区</view>
  13. </picker-view-column>
  14. </picker-view>
  15. </view>
  16. -----------------------------------------------------------------------------------
  17. index.js
  18. --------------
  19. Page({
  20. data: {
  21. value:"海淀",
  22. region:[
  23. "海淀","朝阳","东城","西城","昌平","丰台","大兴","房山","门头沟","石景山","顺义","延庆
  24. ","怀柔","密云","通州"
  25. ]
  26. },
  27. bindChange(e) {
  28. console.log(e)
  29. const val = e.detail.value
  30. var value = this.data.region[val];
  31. this.setData({
  32. value: value
  33. })
  34. }
  35. })