• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

VUE 3 [@vue/compiler-sfc] define Prophotoshop/Emits is a compiler macro and no longer needs to be imported.

武飞扬头像
凉生阿新
帮助1

Vue Vite 项目启动后,控制台报错:

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

[@vue/compiler-sfc] `defineEmits` is a compiler macro and no longer needs to be imported.

警告信息本身意思是:在 <script setup> 中直接使用defineProps\defineEmits,不需要再import。

  1. defineProps、defineEmits 是 Vue 3 的一个特性,用于为组件定义 props。在 Vue 3 中,defineProps、defineEmits 已经成为了编译器宏,不再需要显式地导入。
  2. 总之,defineProps、defineEmits  是 Vue 3 的一个特性,用于为组件定义 props。在 Vue 3 中,defineProps、defineEmits 已经成为了编译器宏,不再需要显式地导入。在使用 defineProps、defineEmits 定义 props、emits 时,它们会自动进行类型检查和默认值设置,使得组件定义更加简洁和易于维护。 

ps:

Vue 3.2 版本后不再需要手动导入 defineProps 和 defineEmits,直接使用即可,官方文档已经更新

eg: 

  1.  
    <script setup>
  2.  
    import { defineProps,defineEmits } from "vue";
  3.  
    .....
  4.  
    </script>

修改:去掉 import 语句即可

  1.  
    <script setup>
  2.  
    const props = defineProps({
  3.  
    name: String
  4.  
    })
  5.  
     
  6.  
    const emit = defineEmits(['del'])
  7.  
    // setup code
  8.  
    </script>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggbgeg
系列文章
更多 icon
同类精品
更多 icon
继续加载