父组件传数据给子组件
- 创建数据
- 获取json数据
子组件传数据给父组件
1. 子组件使用$emit监听数据
getAreaValues(){ this.$emit('getAreaValues', { provId: this.provModel, cityId: this.cityModel, districtId : this.districtModel }) }
2. 在父组件接收,在组件标签使用v-on绑定子组件的同名事件 “getAreaValues”
<template>
<div class="index">
<area-select v-on:getAreaValues="getValue"></area-select>
</div>
</template>
<script>
import areaSelect from './public/selects/areaSelect'
export default {
components: {
areaSelect
},
methods: {
getValue(areaValues){
console.log(areaValues); //组件的返回值
}
}
}
</script>
同级组件之间传数据