vuejs3在Local主机中获得CORS错误
我正在使用http:// localhost:3000来开发我的网站,但是我总是从哨兵那里遇到CROS错误,我缺少什么?
在Sentry的设置中: 域设置为 *,但是看起来不起作用。
我已经将项目的允许 CORS策略:在请求的资源上没有“访问控制”标头。如果不透明的响应满足您的需求,请将请求模式设置为“无核”,以通过禁用CORS来获取资源。
vue3 + vite
yarn add @sentry/tracing @sentry/vue
在main.ts中
import * as Sentry from "@sentry/vue"
import { Integrations } from "@sentry/tracing"
const app = createApp(App)
// Initialize Sentry
const dsnSentry = import.meta.env.VITE_SENTRY_DSN as string
if (!!dsnSentry) {
const env = import.meta.env.VITE_ENV
const isDebug = env !== "production"
Sentry.init({
app,
dsn: dsnSentry,
// integrations: [new Integrations.BrowserTracing()],
integrations: [
new Integrations.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router),
tracingOrigins: ["localhost:3000", /^\//],
}),
],
tracesSampleRate: 1.0,
debug: isDebug,
})
}
app.mount("#app")
I'm using http://localhost:3000 to development my website, but I always get CROS error from Sentry, what am I missing?
in Sentry's Setting:
I've set the project's Allowed Domains to *, but it's looks like not work....
Access to fetch at 'my-sentry-dsn' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
Vue3 + Vite
yarn add @sentry/tracing @sentry/vue
in main.ts
import * as Sentry from "@sentry/vue"
import { Integrations } from "@sentry/tracing"
const app = createApp(App)
// Initialize Sentry
const dsnSentry = import.meta.env.VITE_SENTRY_DSN as string
if (!!dsnSentry) {
const env = import.meta.env.VITE_ENV
const isDebug = env !== "production"
Sentry.init({
app,
dsn: dsnSentry,
// integrations: [new Integrations.BrowserTracing()],
integrations: [
new Integrations.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router),
tracingOrigins: ["localhost:3000", /^\//],
}),
],
tracesSampleRate: 1.0,
debug: isDebug,
})
}
app.mount("#app")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过在
tracingorigins
param中使用*
解决了这个问题。这样:
另一个问题,可以是Ads Block扩展名,例如Adblock,Ublock。
I solved this problem by using
*
in thetracingOrigins
param.Like this:
Another problem, can be ads block extension like adblock, ublock.
对于任何降落在这里的人,我都通过禁用Ublock Origin来修复它...
For whoever lands here, I fixed it by disabling uBlock origin...