- 父元件
傳遞變數時須加上冒號
<template>
<Product :main_category_id="main_category_id" :sub_category_id="sub_category_id"/>
</template>
- 子元件
接收props用法如下
<script setup>
const props = defineProps({
main_category_id: String,
sub_category_id: String
});
//props.main_category_id
</script>
本筆記參考:
1. https://www.netlify.com/blog/understanding-defineprops-and-defineemits-in-vue-3.2
2. https://juejin.cn/post/7111686386645729317