VUE2获取请求地址http://sso.chac.de/ssologout?redirect_uri=http://10.10.24.80:8088/home中的参数
时间: 2023-09-04 22:11:20 浏览: 51
你可以使用以下代码来获取请求地址中的参数:
```javascript
// 获取 URL 中的参数
function getQueryString(name) {
const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
const r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 示例调用
const redirectUri = getQueryString("redirect_uri");
console.log(redirectUri); // http://10.10.24.80:8088/home
```
在上面的代码中,`getQueryString` 函数使用正则表达式来匹配 URL 中的参数,如果找到匹配的参数,则返回该参数的值。你可以将你要获取的参数名作为参数传递给该函数。在示例中,我们通过传递 "redirect_uri" 来获取请求地址中的 "redirect_uri" 参数,并将其赋值给变量 `redirectUri`。
相关问题
http://suggestion.baidu.com/su?cb=getwd&wd=123 这个用jsonp跨域的vue
在 Vue 中,可以使用 `Vue.jsonp` 方法来发送 JSONP 请求,跨域请求百度搜索建议 API 可以按照以下方式实现:
```javascript
Vue.jsonp('http://suggestion.baidu.com/su', {
params: {
wd: '123',
cb: 'getwd'
}
}).then(response => {
console.log(response)
})
```
其中,`params` 参数用于指定请求参数,`cb` 参数指定回调函数的名称。
需要注意的是,由于 JSONP 请求是通过动态创建 `script` 标签实现的,因此在 Vue 中使用 `Vue.jsonp` 发送 JSONP 请求时,需要在页面中放置一个空的 `script` 标签,用于接收服务器返回的数据。可以按照以下方式在 Vue 组件中实现:
```html
<template>
<div></div>
</template>
<script>
export default {
mounted () {
const script = document.createElement('script')
script.src = 'http://suggestion.baidu.com/su?cb=getwd&wd=123'
document.body.appendChild(script)
}
}
</script>
```
在上面的代码中,通过动态创建 `script` 标签,并将其添加到页面中,实现了跨域请求。服务器返回的数据会自动执行 `getwd` 回调函数,并在页面中输出搜索建议的结果。
RENDERER_NODE_ENV=production RENDERER_VUE_APP_PROXY=true RENDERER_VUE_APP_API_BASEURL=http://192.168.1.2:9999 RENDERER_VUE_APP_WS_BASEURL=ws://192.168.1.2:9999/crm/websocket
这是一个包含环境变量的命令,用于设置一个 Vue.js 应用程序的配置选项。具体来说,它设置了以下选项:
- RENDERER_NODE_ENV:设置应用程序的运行环境为生产环境。
- RENDERER_VUE_APP_PROXY:启用代理功能,用于将 API 请求转发到指定的 API 服务器。
- RENDERER_VUE_APP_API_BASEURL:设置 API 服务器的基础 URL,用于创建 API 请求的完整 URL。
- RENDERER_VUE_APP_WS_BASEURL:设置 WebSocket 服务器的基础 URL,用于创建 WebSocket 连接的完整 URL。
这些选项的值分别为:
- RENDERER_NODE_ENV=production:表示应用程序运行在生产环境中。
- RENDERER_VUE_APP_PROXY=true:表示启用了代理功能。
- RENDERER_VUE_APP_API_BASEURL=http://192.168.1.2:9999:表示 API 服务器的基础 URL 为 http://192.168.1.2:9999。
- RENDERER_VUE_APP_WS_BASEURL=ws://192.168.1.2:9999/crm/websocket:表示 WebSocket 服务器的基础 URL 为 ws://192.168.1.2:9999/crm/websocket。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)