问题描述
原因分析
警告信息本身意思是:在 <script setup> 中 直接使用defineProps,不需要再import。
下面是具体的写法:
vue3 setup语法糖:
在 <script setup> 中必须使用 defineProps 和 defineEmits API 来声明 props 和 emits ,它们具备完整的类型推断并且在 <script setup> 中是直接可用的.
修改
<script setup>
const props = defineProps({
foo: String
})
const emit = defineEmits(['change', 'delete'])
// setup code
</script>
参考
单文件组件 https://v3.cn.vuejs.org/api/sfc-script-setup.html#defineprops-%E5%92%8C-defineemits