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”。
- 在tsconfig.json文件中添加 “types”: [“vite/client”]
{
"compilerOptions": {
"types": ["vite/client"]
},
}
- 在src目录下env.d.ts文件中添加
interface ImportMetaEnv {
readonly VITE_BASE_API: string
readonly VITE_BASE_OS: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}