错误合集vue

Getting a value from the propsin root scope of <script setup> will cause the value to lose reactivity.

从props中获取父组件传递数据的时候,不管父组件传递的是不是响应式的数据,在接收的时候要把数据转换为响应式
toRefs(props) 转换所有属性,这样就可以取到了
toRefs :将响应式对象转换为普通对象,其中结果对象的每个 property 都是指向原始对象相应 property 的 ref。

const props = defineProps<{
	fatherRef: any
}>()

const { fatherRef } = props
解决
const { fatherRef } = toRefs(props)

Access to script at 'file:///assets/index.44547315.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

原因:本地创建的项目打包完之后打开index.html 报错
解决方法:全局下载http-server
npm install http-server -g
进入dist/index.html文件 执行http-server
在这里插入图片描述

类型“ImportMeta”上不存在属性“env”。
  1. 在tsconfig.json文件中添加 “types”: [“vite/client”]
{
  "compilerOptions": {
    "types": ["vite/client"] 
  },
}
  1. 在src目录下env.d.ts文件中添加
interface ImportMetaEnv {
	readonly VITE_BASE_API: string
    readonly VITE_BASE_OS: string
} 

interface ImportMeta {
  readonly env: ImportMetaEnv
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值