跳到主要内容

访问 Props

2023年05月02日
柏拉文
越努力,越幸运

一、认识


<script setup> 可以使用 defineProps 接收与 props 选项相同的值。defineProps 只能在 <script setup> 中使用的编译器宏。他们不需要导入,且会随着 <script setup> 的处理过程一同被编译掉。

二、语法


<template>
<div>
{{ a }}
</div>
</template>

<script setup lang="ts">
const props = defineProps({
a: {
type: String,
required: true
}
});
</script>