// components/picker/index.js Component({ /** * 组件的属性列表 */ properties: { title: { type: String, require: true }, prop: { type: String, require: true }, value: { type: String, require: false } }, observers: { // 监听 visible 的变化 'value': function (newVal, oldVal) { if (newVal) { this.setData({ result:newVal }) } } }, /** * 组件的初始数据 */ data: { visible: false, result: '', counts: [] }, /** * 组件的方法列表 */ methods: { init() { var list = [] for (let index = 1; index < 31; index++) { const item = { label: index, value: index } list.push(item) } this.setData({ counts: list }) }, confirm(e) { const value = e.detail.value[0] console.log(e); this.setData({ result: value, visible:false }) this.triggerEvent('ok', { value: {prop: this.data.prop,value:value} }); }, onVisibleChange() { const show = !this.data.visible if (show) { this.init() } this.setData({ visible: show }) }, } })