父组件中
default-value为传递给子组件的值
<x-picker-date id="picker-date" default-value="{{newTime}}"
wx:if="{{showPicker}}" bind:myevent="toggleToast">
</x-picker-date>
父组件js
showPickerDate(e) { this.setData({ showPicker: true }) // 调用子组件中methods的onshow方法 this.selectComponent('#picker-date').onshow() }, // 获取子组件信息 toggleToast(e){ console.log(e.detail) }
子组件js中
properties: { // 父组件传值 defaultValue: { type: String, value: 'default value', } }, methods: { onshow() { console.log(this.data.defaultValue) }, // 传递给父组件 cancelBut: function (e) { var that = this; var myEventDetail = { pickerShow: false, type: 'cancel' } // detail对象,提供给事件监听函数 this.triggerEvent('myevent', myEventDetail) //myevent自定义名称事件,父组件中使用 }, }