// pages/components/selector/selector.js Component({ /** * 组件的属性列表 */ properties: { listData: { type: Array, value: [], } }, /** * 组件的初始数据 */ data: { selectShow: false, index: 0 }, /** * 组件的方法列表 */ methods: { // 点击下拉显示框 /** * 切换选择框的显示状态 * 通过修改selectShow的值来控制选择框的显示/隐藏 */ selectTap() { this.setData({ selectShow: !this.data.selectShow }); }, // 点击下拉列表 optionTap(e) { let Index = e.currentTarget.dataset.index; //获取点击的下拉列表的下标 this.setData({ selectShow: !this.data.selectShow, index: Index }); this.triggerEvent('optionTap', this.data.listData[Index]) }, } })