vue-router打开新的tab页

这段代码展示了如何在Vue应用中利用`$router.resolve`解析路由,并结合`window.open`在新窗口中打开指定路径。通过`const path = '/approval'`定义了目标路由,`query.id`则设置了传递的参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

const path = '/approval' // 路由
const { href } = this.$router.resolve({ path, query: {
    id: res.data
}})
window.open(href, '_blank')
mapbox-gl.js:31 Kr: Not Found at mapbox-gl.js:31:73019 fire @ mapbox-gl.js:31 (匿名) @ mapbox-gl.js:45 h @ mapbox-gl.js:45 (匿名) @ mapbox-gl.js:45 (匿名) @ mapbox-gl.js:31 Promise.then u @ mapbox-gl.js:31 (匿名) @ mapbox-gl.js:31 Hr @ mapbox-gl.js:31 push../node_modules/mapbox-gl/dist/mapbox-gl.js.t.g @ mapbox-gl.js:41 _spriteRequest._spriteRequest @ mapbox-gl.js:45 _loadSprite @ mapbox-gl.js:45 _load @ mapbox-gl.js:45 (匿名) @ mapbox-gl.js:45 (匿名) @ mapbox-gl.js:31 Promise.then c @ mapbox-gl.js:31 (匿名) @ mapbox-gl.js:31 Promise.then u @ mapbox-gl.js:31 (匿名) @ mapbox-gl.js:31 Hr @ mapbox-gl.js:31 push../node_modules/mapbox-gl/dist/mapbox-gl.js.t.g @ mapbox-gl.js:41 loadURL @ mapbox-gl.js:45 load @ mapbox-gl.js:45 _updateStyle @ mapbox-gl.js:45 setStyle @ mapbox-gl.js:45 Map @ mapbox-gl.js:45 initMap @ index.vue:70 mounted @ index.vue:64 invokeWithErrorHandling @ vue.runtime.esm.js:1854 callHook @ vue.runtime.esm.js:4213 insert @ vue.runtime.esm.js:3139 invokeInsertHook @ vue.runtime.esm.js:6340 patch @ vue.runtime.esm.js:6559 Vue._update @ vue.runtime.esm.js:3942 updateComponent @ vue.runtime.esm.js:4060 get @ vue.runtime.esm.js:4473 run @ vue.runtime.esm.js:4548 flushSchedulerQueue @ vue.runtime.esm.js:4304 (匿名) @ vue.runtime.esm.js:1980 flushCallbacks @ vue.runtime.esm.js:1906 Promise.then timerFunc @ vue.runtime.esm.js:1933 nextTick @ vue.runtime.esm.js:1990 queueWatcher @ vue.runtime.esm.js:4396 update @ vue.runtime.esm.js:4538 notify @ vue.runtime.esm.js:730 reactiveSetter @ vue.runtime.esm.js:1055 (匿名) @ vue-router.esm.js:2503 (匿名) @ vue-router.esm.js:2502 updateRoute @ vue-router.esm.js:1989 (匿名) @ vue-router.esm.js:1867 (匿名) @ vue-router.esm.js:1976 step @ vue-router.esm.js:1706 step @ vue-router.esm.js:1713 step @ vue-router.esm.js:1713 runQueue @ vue-router.esm.js:1717 (匿名) @ vue-router.esm.js:1971 step @ vue-router.esm.js:1706 (匿名) @ vue-router.esm.js:1710 (匿名) @ vue-router.esm.js:1956 (匿名) @ vue-router.esm.js:1749 (匿名) @ vue-router.esm.js:1825 (匿名) @ permission.js:108 Promise.then component @ permission.js:108 (匿名) @ vue-router.esm.js:1766 (匿名) @ vue-router.esm.js:1793 (匿名) @ vue-router.esm.js:1793 flatMapComponents @ vue-router.esm.js:1792 (匿名) @ vue-router.esm.js:1728 iterator @ vue-router.esm.js:1935 step @ vue-router.esm.js:1709 step @ vue-router.esm.js:1713 step @ vue-router.esm.js:1713 (匿名) @ vue-router.esm.js:1710 (匿名) @ vue-router.esm.js:1956 _callee$ @ permission.js:100 tryCatch @ regeneratorRuntime.js:45 (匿名) @ regeneratorRuntime.js:133 (匿名) @ regeneratorRuntime.js:74 asyncGeneratorStep @ asyncToGenerator.js:3 _next @ asyncToGenerator.js:17 (匿名) @ asyncToGenerator.js:22 (匿名) @ asyncToGenerator.js:14 (匿名) @ permission.js:176 iterator @ vue-router.esm.js:1935 step @ vue-router.esm.js:1709 runQueue @ vue-router.esm.js:1717 confirmTransition @ vue-router.esm.js:1964 transitionTo @ vue-router.esm.js:1866 replace @ vue-router.esm.js:2279 (匿名) @ vue-router.esm.js:1950 _callee$ @ permission.js:155 tryCatch @ regeneratorRuntime.js:45 (匿名) @ regeneratorRuntime.js:133 (匿名) @ regeneratorRuntime.js:74 asyncGeneratorStep @ asyncToGenerator.js:3 _next @ asyncToGenerator.js:17 Promise.then asyncGeneratorStep @ asyncToGenerator.js:8 _next @ asyncToGenerator.js:17 Promise.then asyncGeneratorStep @ asyncToGenerator.js:8 _next @ asyncToGenerator.js:17 Promise.then asyncGeneratorStep @ asyncToGenerator.js:8 _next @ asyncToGenerator.js:17 Promise.then asyncGeneratorStep @ asyncToGenerator.js:8 _next @ asyncToGenerator.js:17 (匿名) @ asyncToGenerator.js:22 (匿名) @ asyncToGenerator.js:14 (匿名) @ permission.js:176 iterator @ vue-router.esm.js:1935 step @ vue-router.esm.js:1709 runQueue @ vue-router.esm.js:1717 confirmTransition @ vue-router.esm.js:1964 transitionTo @ vue-router.esm.js:1866 init @ vue-router.esm.js:2494 beforeCreate @ vue-router.esm.js:539 invokeWithErrorHandling @ vue.runtime.esm.js:1854 callHook @ vue.runtime.esm.js:4213 Vue._init @ vue.runtime.esm.js:4998 Vue @ vue.runtime.esm.js:5079 ./src/main.js @ main.js:75 __webpack_require__ @ bootstrap:766 fn @ bootstrap:129 1 @ app.js:297546 __webpack_require__ @ bootstrap:766 (匿名) @ bootstrap:901 (匿名) @ bootstrap:901
最新发布
08-26
<think>我们正在处理用户关于Mapbox GL JS的错误:"mapbox-gl.js error Kr: Not Found at line 31:73019" 根据错误信息,这通常是由于资源加载失败引起的。可能的原因包括: 1. Mapbox GL JS库文件或相关资源(如样式、字体、图标等)的URL不正确或不可访问。 2. 网络问题导致资源加载失败。 3. 访问令牌(access token)无效或未设置。 解决步骤: 1. 检查Mapbox GL JS库的引入是否正确,确保使用的是有效的CDN地址。 2. 检查访问令牌(access token)是否设置且有效。 3. 检查网络请求,查看哪些资源加载失败(使用浏览器开发者工具)。 根据引用[1](快速入门Mapbox GL JS)中的内容,正确设置Mapbox GL JS的基本步骤包括: - 引入Mapbox GL JS的CSS和JavaScript文件。 - 设置有效的访问令牌。 -面中指定一个容器用于地图。 示例代码片段: ```html <!DOCTYPE html> <html> <head> <meta charset='utf-8' /> <title>Quick Start</title> <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script> <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' /> <style> body { margin:0; padding:0; } #map { position:absolute; top:0; bottom:0; width:100%; } </style> </head> <body> <div id='map'></div> <script> // 设置访问令牌 mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN'; var map = new mapboxgl.Map({ container: 'map', // 容器ID style: 'mapbox://styles/mapbox/streets-v12', // 地图样式 center: [-74.5, 40], // 初始中心点 zoom: 9 // 初始缩放级别 }); </script> </body> </html> ``` 错误分析: - 错误信息中的“Kr: Not Found”可能指的是某种资源(可能是字体、图标或瓦片)未找到。 - 在Mapbox GL JS中,字体和图标通常是从Mapbox服务器加载的,如果访问令牌无效或者网络问题,就会导致加载失败。 具体解决建议: 1. 确保访问令牌(accessToken)设置正确且有效。可以在Mapbox官网的账户面生成或查看令牌。 2. 检查网络连接,确保可以访问Mapbox的服务(例如,尝试在浏览器中打开Mapbox的样式URL)。 3. 使用浏览器开发者工具(按F12)查看网络请求,找到失败的请求(状态为404或403等),然后根据失败的URL进一步排查。 4. 如果使用的是自定义样式,确保样式中的资源(如字体、图标)存在并且可访问。 如果问题仍然存在,可以尝试更Mapbox GL JS的版本,因为旧版本可能存在已知问题。 另外,引用[2]中提到了一些插件,但与本错误关系不大,不过如果使用了相关插件,也要确保插件的资源路径正确。 综上所述,重点检查访问令牌和资源路径。 生成相关问题: 1. 如何获取Mapbox访问令牌? 2. 如何解决Mapbox GL JS中的网络错误? 3. Mapbox GL JS中常见的错误有哪些?</think>### Mapbox GL JS 错误 "Kr: Not Found" 解决方案 该错误通常由**资源加载失败**引起,以下是系统化的排查步骤: #### 1. **检查访问令牌 (Access Token)** - 确保在初始化地图前正确设置了有效的访问令牌: ```javascript mapboxgl.accessToken = 'YOUR_ACCESS_TOKEN'; // 替换为真实令牌 ``` - 验证令牌权限: - 登录 [Mapbox 账户](https://account.mapbox.com/) → 检查令牌是否激活且具有`styles:read`、`fonts:read`权限 - 测试令牌有效性: ```bash curl "https://api.mapbox.com/styles/v1/mapbox/streets-v12?access_token=YOUR_TOKEN" ``` #### 2. **验证资源路径** - 检查地图样式 URL 是否有效: ```javascript new mapboxgl.Map({ style: 'mapbox://styles/mapbox/streets-v12' // 标准样式 // 避免使用自定义样式路径如 mapbox://styles/yourname/xxxx }); ``` - 若使用自定义样式: 1. 在 [Mapbox Studio](https://studio.mapbox.com/) 中确认样式已发布 2. 检查样式中的字体/图标源是否存在: ```json "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf" // 标准路径 ``` #### 3. **排查网络请求** - 在浏览器开发者工具(F12)中: 1. 切换到 **Network 选项卡** 2. 过滤 `pbf` 或 `font` 类型请求 3. 检查失败请求的 HTTP 状态码: - `404`:资源路径错误 - `401`:令牌无效 - `403`:令牌权限不足 ![Network Tab示例](https://i.imgur.com/8XGQ1tL.png) #### 4. **更库版本** - 使用最稳定版(当前 v2.14.1): ```html <!--CSS和JS链接 --> <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script> <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' /> ``` #### 5. **测试最小化案例** ```html <!DOCTYPE html> <html> <head> <script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script> <link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet'> </head> <body> <div id="map" style="width:600px;height:400px"></div> <script> mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD4S'; new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v12' }); </script> </body> </html> ``` ### 常见触发场景 1. **本地开发环境** - 问题:跨域请求被拦截 - 解决:添加本地域名到 Mapbox 白名单(账户 → Domains) 2. **字体资源缺失** - 错误日志:`Failed to load glyphs from ...` - 方案:在样式中替换为默认字体源 ```json "glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf" ``` 3. **令牌权限不足** - 需确保令牌包含以下权限: - `styles:tiles` - `fonts:read` - `styles:read` > **重要提示**:90%的"Kr: Not Found"错误由**无效令牌**或**错误样式路径**导致。优先检查这两项[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值