子组件<Quarter.vue>
想要把selectSeason方法里面的showValue值传到父组件中
这一块很简单
selectSeason(i) {
let that = this
that.season = i + 1
let arr = that.valueArr[i].split('-')
that.getValue(that.year + arr[0] + '-' + that.year + arr[1])
that.showSeason = false
this.showValue = `${this.year}年${this.season}季度`
this.$emit('toFind', this.showValue)
},
$emit(传输的名字(自定义),想传的值)
父组件<find.vue>中先部署调用子组件,这个不会就过份啦😄
import Quarter from "./Quarter";
components: {
Quarter
},
在template中使用,先获取到自定义的传输名字,给他赋值到一个自定义的方法上面去
<template>
...
...
...
<Quarter @toFind="getData"></Quarter>
...
...
</template>
下面就获取到值了
methods:{
.....
.....
getData(data){
console.log(data)
},
.....
....
}
是不是炒鸡简单,如果发现不成功,或者调不通,那应该是命名的问题,多换几个不重复的名字,我就是一开始名字重复,坑死我了,我太难了!!!!