子组件通过$emit传递数值
<!--子组件传值到父组件 通过$emit-->
<template>
<view class="leave_cont">
<view class="flex1">
<view>日期: </view>
<picker mode="date" :value="start_date" :start="start_date" :end="other" @change="bindDateChange">
{{start_date}}
</picker>
</view>
<view class="flex1">
<view>至: </view>
<picker mode="date" :value="start_date" :start="start_date" @change="bindDateChange2">
{{other}}
</picker>
</view>
</view>
</template>
export default {
data() {
const currentDate = this.getDate({
format: true
})
return {
start_date: '开始时间', //传递给父组件的开始日期
end_date: currentDate,
other: '结束日期' //传递父组件的结束日期
}
},
watch:{
start_date(val){
//通过$emit向父组件传值
//this.$emit('父组件绑定名称',值1,值2)
this.$emit('getTime1',this.start_date,this.other)
},
other(val){
this.$emit('getTime1',this.start_date,this.other)
}
},
}
父页面
<view class="chooise-box">
<!-- 使用日期组件 -->
<startime @getTime1="getTime2"></startime>
</view>
<script>
//引用组件
import startime from '../statendtime.vue'
export default {
components: {
//挂载组件
startime,
},
data() {
return {
};
},
methods: {
// 获取子组件数据
getTime2(start,end){
console.log(start,end)
},
}
}
</script>
仅供自己整理,不做他用