vue3 -script-setup 子组件与父组件之间传值

2021-07-09  本文已影响0人  小李不小

通过父组件 传递 msg 变量过去。

<template>
  <HelloWorld  msg="Hello Vue 3.0 + Vite  传过来的" />
</template>

<script setup>
import HelloWorld from './components/HelloWorld.vue'

</script>

<template>
  <h1>{{ msg }}</h1>
</template>

<script setup>
// defineProps 接收
  import {defineProps} from 'vue'

  const props =defineProps({  //获取传参的数据
    msg:String,
  })
  

</script>

看结果 值被传过来的

上一篇 下一篇

猜你喜欢

热点阅读