路由传值及获取参数,路由跳转,路由检测,this.$route.query和this.$route.params接收参数,HttpGet请求拼接url参数
配置动态路由参数id:
routes: [
// 动态路径参数 以冒号开头
{ path: '/user/:id', component: User }
]
html路由跳转:
<router-link to="/demo53/8">路径参数跳转</router-link>
①不带参数写法:
<router-link to="home">点我</router-link>
<router-link v-bind:to="'home'">点我</router-link>
<router-link :to="'home'">Home</router-link>
<router-link :to="{ path: 'home' }">Home</router-link>
② 带参数写法:
A: <router-link :to="{ name: 'user', params: { userId: 123 }}">User</router-link>
批注:路由配置格式:
{ path: '/user/:userId', name: 'user', component: User }
导航显示:/user/123
B: <router-link :to="{ path: 'register', query: { plan: 'private' }}">Register</router-link>
批注:带查询参数
导航显示:/register?plan=private
js中使用的方式:
① this.$router.push('xxx') //字符串,这里的字符串是路径path匹配噢,不是router配置里的name
② this.$router.push({ path: 'home' }) //对象
③ this.$router.push({ name: 'user', params: { userId: 123 }}) // 命名的路由 这里会变成 /user/123
④ this.$router.push({ path: 'register', query: { plan: 'private' }}) // 带查询参数,变成 /register?plan=private
vue之this.$route.query和this.$route.params接收参数
this.$route.query
A页面传递参数peng=
registerInfoThis.$router.push("/hrhi/psninfo/dynamic/" + data.row.pk_psndoc + '?funcode=60070psninfo&peng=0');
B页面接收参数
created() {
this.penga = this.$route.query["peng"];
},
‘http://localhost:8080/linkParamsQuestion?age=18’
let age = this.$route.query.age; //问号后面参数会被封装进 this.$route.query;
this.$route.params
、router/index.js
{
path:'/mtindex',
component: mtindex,
//添加路由
children:[
{
path:"/detail",
name:'detail',
component:guessdetail
}
] }, 、传参数( params相对应的是name query相对应的是path)
this.$router.push({
name: ‘detail’, params:{shopid: item.id}
}); 、获取参数
this.$route.params.shopid 、url的表现形式(url中没带参数)
http://localhost:8080/#/mtindex
.检测路由
watch:{
'$route': function (to,from) {
// 对路由变化作出响应...
}
}
或者
watch: {
"$route": "routeChange",
},
methods: {
routeChange(){
console.log(this.$route.path);
}
}
在 router-view上加上一个唯一的key,来保证路由切换时都会重新渲染触发钩子了
<router-view :key="key"></router-view>
computed: {
key() {
return this.$route.name !== undefined? this.$route.name + +new Date(): this.$route + +new Date()
}
}
HttpGet请求拼接url参数
const query = {
client_id: state.auth.clientID,
redirect_uri: location.href,
scope: 'public_repo'
}
const queryString = Object.keys(query)
.map(key => `${key}=${encodeURIComponent(query[key] || '')}`)
.join('&')
return `http://github.com/login/oauth/authorize?${queryString}`
return vue.$http.get(`https://api.github.com/search/issues?q=${data.keyword}+state:open+repo:${vue.$store.getters.repo}${label}&sort=created&order=desc&page=${data.currentPage}&per_page=${data.pageSize}`, {
headers: {
'Accept': 'application/vnd.github.v3.html'
}
})
url参数转json字符串:
const queryParse = (search = window.location.search) => {
if (!search) {
return {}
} else {
const queryString = search[] === '?' ? search.substring() : search
const query = {}
queryString
.split('&')
.forEach(queryStr => {
const [key, value] = queryStr.split('=')
if (key) {
query[decodeURIComponent(key)] = decodeURIComponent(value)
}
})
return query
}
}
const queryStringify = query => {
const queryString = Object.keys(query)
.map(key => `${key}=${encodeURIComponent(query[key] || '')}`)
.join('&')
return queryString
}
//方法封装
function GetRequest() {
//获取url中"?"符后的字串
var url = location.search;
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
}
}
return theRequest;
}
// 方法调用
var Request = new Object();
Request = GetRequest();
var urlCan = Request['参数名'];
function getUrlParam(key) {
// 获取参数
var url = window.location.search;
// 正则筛选地址栏
var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
// 匹配目标参数
var result = url.substr(1).match(reg);
//返回参数值
return result ? decodeURIComponent(result[2]) : null;
}
//调用
getUrlParam("参数名");
https://www.cnblogs.com/websmile/p/7873601.html vue-router的用法
https://blog.csdn.net/zjl199303/article/details/82655576 vue 配置路由 + 用户权限生成动态路由 踩过的那些坑
https://blog.csdn.net/sangjinchao/article/details/70888259 vue,router-link传参以及参数的使用
https://blog.csdn.net/wojiaomaxiaoqi/article/details/80688911 vue中this.$router.push路由传参以及获取方法
路由传值及获取参数,路由跳转,路由检测,this.$route.query和this.$route.params接收参数,HttpGet请求拼接url参数的更多相关文章
- 为什么返回的数据前面有callback? ashx/json.ashx?的后面加 callback=? 起什么作用 js url?callback=xxx xxx的介绍 ajax 跨域请求时url参数添加callback=?会实现跨域问题
为什么返回的数据前面有callback? 这是一个同学出现的问题,问到了我. 应该是这样的: 但问题是这样的: 我看了所请求的格式和后台要求的也是相同的.而且我也是这种做法,为什么他的就不行呢? ...
- vue中this.$router.push()路由传值和获取的两种常见方法
1.路由传值 this.$router.push() (1) 路由跳转使用router.push()方法,这个方法会向history栈添加一个新纪录,所以,当用户点击浏览器后退按钮时,会回到之前的 ...
- HttpGet 请求(带参数)
package com.example.util; import java.io.BufferedReader;import java.io.IOException;import java.io.In ...
- HttpClient4.X发送Get请求的url参数拼接
HttpClient4.X发送Get请求的参数拼接 使用httpClient发送get请求时,请求参数可以以?key=val&key1=val1的拼接到url后面. 但是请求参数较多时,这种方 ...
- ajax 跨域请求时url参数添加callback=?会实现跨域问题
例如: 1.在 jQuery 中,可以通过使用JSONP 形式的回调函数来加载其他网域的JSON数据,如 "myurl?callback=?".jQuery 将自动替换 ? 为正确 ...
- Spring+MVC Controller层接收App端请求的中文参数乱码问题。
在正文之前,说明下Filter的作用: 过滤器顾名思义就是进行过滤的,可以实现代码的定向执行和预处理.通俗点说法filter相当于加油站,request是条路,response是条路,目的地是serv ...
- 获取移除指定Url参数(原创)
/// <summary> /// 移除指定的Url参数 /// 来自:http://www.cnblogs.com/cielwater /// </summary> /// ...
- react-router url参数更新 但是页面不更新的解决办法
今天发现, 当使用react-router(v4.2.2)时,路由需要传入参数, 但是如果路由跳转时,url仅仅改变的是参数部分,如从hello/1跳转到hello/2,此时虽然参数更新了,但是页面是 ...
- 使用Typescript重构axios(三)——实现基础功能:处理get请求url参数
0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...
随机推荐
- 轻量级标记语言Asciidoc、Markdown
Asciidoc简介 https://blog.csdn.net/u011411849/article/details/79031718 Asciidoc 比Markdown更简洁强大的文档工具 ht ...
- CSS浮动特性
float:left/right左浮动有浮动 特点: ①浮动不占位:浮动元素不占位置 ②默认排列成一行,遇到边界自动换行 ③如果有文字(没有设置浮动的元素内容)会绕着浮动元素走 <!DOCTYP ...
- [Python] Codecombat 攻略 Sarven 沙漠 (1-43关)截止至36关
首页:https://cn.codecombat.com/play语言:Python 第二界面:Sarven沙漠(43关)时间:4-11小时内容:算术运算,计数器,while循环,break(跳出循环 ...
- evpp http put问题
https://blog.csdn.net/yuzuyi2006/article/details/82112664 最近做了一个项目需要实现web服务,使用了evpp.但是在用的过程中碰到了http ...
- 优先级:content –> width –> flex-basis (limted by max|min-width)
原文: https://www.jianshu.com/p/17b1b445ecd4 -------------------------------------------- 最近在学习Flex Bo ...
- 《流畅的Python》Object References, Mutability, and Recycling--第8章
Object References, Mutability, and Recycling 本章章节: Variables Are Not Boxes identity , Equality , Al ...
- LeetCode刷题--有效的括号(简单)
题目描述 给定一个只包括 ' ( ' , ' ) ', ' { ' , ' } ' , ' [ ' , ' ] ' 的字符串,判断字符串是否有效.有效字符串需满足: 左括号必须用相同类型的右括号闭 ...
- python yaml文件内容的读取
示例: (1)host_header.yaml 文件中的内容 host: https://testapp.goodiber.com/v2/ #dev1的测试环境域名 #请求接口的请求头中的共用参数 ...
- 【模板】A*B Problem升级版(FFT快速傅里叶)
题目描述 给出两个 $n$ 位10进制数x和y,求x*y(详见 洛谷P1919) 分析 假设已经学会了FFT/NTT. 高精度乘法只是多项式乘法的特殊情况,相当于$x=10$ 时. 例如n=3,求12 ...
- Sql中partition by的使用
partition by关键字是oracle中分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分 ...