【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