Vue3 父组件传值到子组件

父组件

<template>
  <HelloWorld :test="testData" testStr="父组件传一个字符串到子组件"/>
</template>

<script setup  name="App" >
import HelloWorld from './components/HelloWorld.vue';
let testData={
  code:1,
  msg:"父组件传值到子组件"
}
</script>

子组件

<template>
  <div class="HelloWorld">
    <p>{{ props.test.code }}</p>
    <p>{{ props.test.msg }}</p>
    <p>{{ props.testStr }}</p>
  </div>
</template>

<script setup name="HelloWorld">
import { defineProps } from 'vue';
const props = defineProps({
  test: Object,
  testStr:String
})
</script>

本文来自 www.luofenming.com