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

Vue Vite项目启动后,控制台报错: [@vue/compiler-sfc] defineProps is a compiler macro and no longer needs to be imported.

具体报错提示如:

终端使用 npm run dev 启动项目

$ npm run dev            

> vite-project@0.0.0 dev
> vite
Pre-bundling dependencies:
  vue
(this will be run only when your dependencies or config have changed)
  vite v2.5.0 dev server running at:
  > Local: http://localhost:3000/
  > Network: use `--host` to expose
  ready in 1140ms.

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

这是使用 vite 初始化生成的项目,什么都还也没改呢,怎么就报错。

提示说: ‘defineProps’ 是一个编译宏,不再需要导入。

看看哪里引入defineProps了呢?

搜索项目,在HelloWorld.vue中里发现了它:

即文件: vite-project/src/components/HelloWorld.vue

<template>
  <h1>{{ msg }}</h1>
</template>
<script setup>
import { defineProps, reactive } from 'vue'

defineProps({
  msg: String
})

const state = reactive({ count: 0 })
</script>

解决办法:

将这句:

import { defineProps, reactive } from 'vue'

改成:

import { reactive } from 'vue'

即,删除 defineProps 的引入。

重新运行 npm run dev 即可。

估计是改了语法,但是实例项目没有更新导致的。


【END】

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Web后端技术

您的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值