父组件向子组件传值
父组件向子组件传值即子组件通过props接收父组件传过来的值
<template>
<!--父组件-->
<!--父组件向子组件传值-->
<div>
<childComponent :childValue = 'fatherValue'></childComponent>
</div>
</template>
<script>
import childComponent from '../taskOne/index'
export default {
data(){
return{
//下面这个值传给子组件
fatherValue:'我是父组件的值',
}
},
components:{childComponent}
}
</script>
<style>
</style>
<template>
<!--子组件-->
<!--子组件接收父组件传来的值-->
<div>
<h3>{{childValue}}</h3>
</div>
</template>
<script>
export default {
props:{
childValue:String,
},
data(){
return{
}
}
}
</script>
<style>
</style>