【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>
posted @ 2022-02-06 14:14  MegaSu  阅读(9593)  评论(0编辑  收藏  举报