Vue3.0的父子传值
1.父组件向子组件传值
父组件:
<template>
<div>
<h1>父组件<h1>
<hr>
<son :money="money">
</div>
</template>
<script>
import {ref} from 'vue'
import son from './son.vue'
export default {
name:'App',
components:{
Son
}
//父组件的数据传递给子组件
setup(){
const money = ref(100);
return {money}
}
}
</script>
注:Vue3.0中父组件向子组件中传值和Vue2.0中传值一样只不过要按照Vue自己的方式将自己的数据变成响应式的数据进行绑定。
子组件:
<template>
<div>
<h1>子组件</h1>
<hr>
<div>{
{money}}</div>
</div>
</template>
<script>
import {onMounted} from 'vue'
export default{
name:'App',
props:{
money:{
type:Number