这里就以setup语法糖来介绍,因为毕竟setup语法糖还是更方便些嘛
1. 父传子
父传子的话,父组件没什么不同,还是跟之前一样的写法、一样的操作,我们主要关心子组件接受的方式,常用有两种方式如下:
先上个父组件的代码
<template>
<h1>我是父组件</h1>
<Comp :msg="msg" :info="info" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import Comp from '@/components/Comp.vue'
const msg = ref('message')
const info = ref({
id: 0,
name: 'wft',
color: 'red'
})
</script>
然后子组件接受
方式一:
<template>
<div :style="{ backgr