let q = decodeURIComponent(options.q) // 获取到二维码原始链接内容 // const scancode_time = parseInt(options.scancode_time) // 获取用户扫码时间 UNIX 时间戳 let backUrl = this.options.backUrl // console.log(this.getQueryVariable(q).parkId) if (this.options.type === undefined) { if(q && q != 'undefined') { console.log(q) backUrl = this.getQueryVariable(q).native if(this.getQueryVariable(q).id && this.getQueryVariable(q).id != 'undefined'){ backUrl = this.getQueryVariable(q).native +'?id='+ this.getQueryVariable(q).id } } }
时间: 2024-04-19 20:29:51 浏览: 7
这段代码是用来解码二维码的原始链接内容,并获取相关参数进行处理。首先,通过`decodeURIComponent`方法对`options.q`进行解码,获取二维码原始链接内容。然后,判断`this.options.type`是否为undefined,如果是的话,再判断`q`是否存在且不等于'undefined'。如果满足条件,则打印出`q`的值,并将`backUrl`赋值为通过`getQueryVariable`方法获取到的原生链接。接着,再判断`q`中是否存在id,并且不等于'undefined',如果存在,则将`backUrl`赋值为原生链接加上id参数。最后,根据需求处理完相关参数后的`backUrl`。
相关问题
to="../compay/compay?id={{item.id}}” 中的itemid
如果 `to` 属性中的 `item.id` 是一个字符串类型的参数,可以先使用 `encodeURIComponent()` 方法对其进行编码,然后在目标页面中使用 `decodeURIComponent()` 方法进行解码。
在源页面中的代码可以这样写:
```html
<uni-list>
<uni-list-item navigator to="../compay/compay?id={{encodeURIComponent(item.id)}}">
{{item.title}}
</uni-list-item>
</uni-list>
```
在目标页面中的代码可以这样写:
```javascript
onLoad: function(options) {
console.log(decodeURIComponent(options.id));
}
```
这样就可以正确地获取传递过来的参数了。
router.beforeEach((to, from, next) => { if (store.getters.getRouters == null) { // 获取菜单和路由 getMenusApi(params).then((res) => { if (res.data.length === 0) { window.location.href = process.env.VUE_APP_API_BASE_CONSOLE || '' } const { data } = res const menuNav = [] const childrenNav = [] // 后端数据, 根级树数组, 根级 PID listToTree(data, childrenNav, 0) menuNav.push(...childrenNav) const routers = generator(menuNav, null) routers.forEach((r) => { router.addRoute(r) }) router.addRoute(page404) store.commit('SET_ROUTERS', routers[0].children) // 请求带有 redirect 重定向时,登录自动重定向到该地址 const redirect = decodeURIComponent(from.query.redirect || to.path) if (to.path === redirect) { // set the replace: true so the navigation will not leave a history record next({ ...to, replace: true }) } else { // 跳转到目的路由 next({ path: redirect }) } }).catch((error) => { console.log(error,'error') if (error.data.code !== 200 || error.data.data.length === 0) { setTimeout(function () { window.location.href = process.env.VUE_APP_API_BASE_CONSOLE || '' }, 5) } }) // // 获取按钮权限 // getPermissionApi(params).then((res: any) => { // if (res.data.code !== 200) return ElMessage.error(res.data.message) // store.commit('SET_PERMISSION', res.data.data) // }) // // 获取数据权限 // getRolesApi(params).then((res: any) => { // if (res.data.code !== 200) return ElMessage.error(res.data.message) // store.commit('SET_ROLES', res.data.data) // }) // // 获取用户信息 // getUserInfoApi().then((res: any) => { // if (res.data.code !== 200) return ElMessage.error(res.data.message) // store.commit('SET_USERS', res.data.data) // }) } else { next() } })
这是一个 Vue 路由守卫的代码片段,用于在路由切换前进行一些操作。其中包含了以下主要逻辑:
1. 判断 store 中的路由信息是否为空,如果为空则向后端发起请求获取菜单和路由信息。
2. 通过 getMenusApi 函数向后端发起请求,获取菜单和路由信息。如果请求成功,则将获取到的菜单和路由信息转换为前端路由,并添加到 Vue Router 中。
3. 如果请求带有 redirect 重定向参数,则自动跳转到该地址。
4. 如果 store 中已经有路由信息,则直接跳转到目的路由。
5. 如果获取菜单和路由信息失败,则跳转到 404 页面或者登录页面。
注释中的代码是一些额外的逻辑,用于获取用户信息、按钮权限、数据权限等。