别人提过的问题,这里就重复描述了,直接上链接
vue3 setup语法通过defineProps获取props为null
首先看源码中的注释
/**
* Vue `<script setup>` compiler macro for declaring a component's emitted
* events. The expected argument is the same as the component `emits` option.
*
* Example runtime declaration:
* ```js
* const emit = defineEmits(['change', 'update'])
* ```
*
* Example type-based declaration:
* ```ts
* const emit = defineEmits<{
* // <eventName>: <expected arguments>
* change: []
* update: [value: string] // named tuple syntax
* }>()
*
* emit('change')
* emit('update', 1)
* ```
*
* This is only usable inside `<script setup>`, is compiled away in the
* output and should **not** be actually called at runtime.
*
* @see {@link https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits}
*/
// overload 1: runtime emits w/ array