【Bug记录】[@vue/compiler-sfc] `defineProps` is a compiler macro and no longer needs to be imported.


【Bug记录】[@vue/compiler-sfc] defineProps is a compiler macro and no longer needs to be imported.

Vue3项目遇到编译警告

image

image

错误翻译

  • 英文:[@vue/compiler-sfc]
  • 翻译:Vue 单文件组件 (SFC) 编译警告。
  • 原文:defineProps is a compiler macro and no longer needs to be imported.
  • 翻译:defineProps 只是编译器宏,不再需要导入。
  • 原文:defineEmits is a compiler macro and no longer needs to be imported.
  • 翻译:defineEmits 只是编译器宏,不再需要导入。

错误归因

  • 项目使用 <script setup> 语法糖。
  • 通过 import 导入了 definePropsdefineEmits
  • Vue3.2 版本后 definePropsdefineEmits 无需导入

官方文档已更新

image

解决方案🎯

🎯 删除 definePropsdefineEmits 的导入语句即可,对象项目没有造成任何影响。
参考代码如下:

<script setup lang="ts">
// 🎯 删除 `defineProps` 或 `defineEmits` 的导入语句即可。
-import { defineProps, defineEmits } from 'vue-demi'
const props = defineProps({
  modelValue: {
    type: Boolean
  }
})
const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
  (e: 'change', value: boolean): void
}>()
// ...其他代码省略
</script>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM