063——VUE中vue-router之重定向redirct的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue-router之重定向redirct的使用</title>
<script src="vue.js"></script>
<script src="node_modules/vue-router/dist/vue-router.js"></script>
</head>
<body>
<div id="demo">
<router-link to="/">首页</router-link>
<router-link to="/about">关于我们</router-link>
<router-view></router-view>
</div>
<script type="text/x-template" id="home">
<div>
<li v-for="v in news"> <a href="#" @click.prevent="go(v.id)">{{v.title}}</a>
</li>
</div>
</script>
<script type="text/x-template" id="content">
<div>
<h1>{{field.title}}--{{field.id}}</h1>
<p>
{{field.content}}
</p>
<a href="" @click.prevent="back()">返回首页</a>
</div>
</script>
<script>
var data = [
{id: 1, title: "php课程", content: "php是个比较牛的技术"},
{id: 2, title: "java课程", content: "java是个比较牛的技术"},
{id: 3, title: "pathon课程", content: "pathon是个比较牛的技术"}
]
const home = {
template: "#home",
data() {
return {
news: data
}
},
methods:{
go(id){
//var url='/content/'+id; //url第一种写法
//var url={name:'content',params:{id:id}};//url第二种写法
//this.$router.replace(url);//replace()替换历史记录中的跳转: var url={'path':'/content/'+id};//跳转到详情页 //url第三种写法
this.$router.push(url);
}
}
}
const content = {
template: "#content",
data() {
return {
field: {}
}
},
mounted() {
var id = this.$route.params.id;
for (let k = 0; k < data.length; k++) {
if (data[k].id == id) {
this.field = data[k];
}
}
},
methods:{
back(){
this.$router.go(-1);
}
}
}
let routes = [
{path: '/', component: home},
{path: '/content/:id', component: content, name: "content"},
{path: '/about', redirect:{name:'content',params:{id:3}}}
];
//把组件交给路由器:
let router = new VueRouter({routes});
new Vue({
el: "#demo",
router
});
</script>
</body>
</html>
063——VUE中vue-router之重定向redirct的使用的更多相关文章
- 【面试题】Vue中的$router 和 $route的区别
Vue中的$router 和 $route的区别 点击视频讲解更加详细 this.$route:当前激活的路由的信息对象.每个对象都是局部的,可以获取当前路由的 path, name, params, ...
- Vue中this.$router.push(参数) 实现页面跳转
很多情况下,我们在执行点击按钮跳转页面之前还会执行一系列方法,这时可以使用 this.$router.push(location) 来修改 url,完成跳转. push 后面可以是对象,也可以是字符串 ...
- vue中的router和route有什么区别?
我只知道前者一般用在跳转路由的时候,push一个url, 而后者则用来存储路由跳转过程中存储的各种数据. 话不多说,这篇博客讲的比较详细,可以参考一下. vue2.0中的$router 和 $rout ...
- vue中使用router全局守卫实现页面拦截
一.背景 在vue项目中使用vue-router做页面跳转时,路由的方式有两种,一种是静态路由,另一种是动态路由.而要实现对路由的控制需要使用vuex和router全局守卫进行判断拦截(安全问题文章最 ...
- vue中的$router 和 $route的区别
最近在学习vue的单页面应用开发,需要vue全家桶,其中用到了VueRouter,在路由的设置和跳转中遇到了两个对象$router 和 $route ,有些傻傻分不清,后来自己结合网上的博客和自己本地 ...
- vue 中的router 配置问题 导致的内存溢出~~~
最近的项目用到 vue, 各种踩坑中. 其中一个就是router映射表写的稍有不慎,就会出现内存溢出的问题, 而且也不会具体告诉你哪里出错,所以很是头疼~~~ 出错多了,发现了一些router的一些规 ...
- Vue中this.$router.push参数获取
传递参数的方法:1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中path不能和params一起使用,否则params将无效.需要用name来 ...
- vue 中 this.$router.push() 路由跳转传参 及 参数接收的方法
传递参数的方法:1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效.需要用name ...
- Vue中this.$router.push参数获取(通过路由传参)【路由跳转的方法】
传递参数的方法: 1.Params 由于动态路由也是传递params的,所以在 this.$router.push() 方法中 path不能和params一起使用,否则params将无效.需要用nam ...
- vue中this.$router.push()路由传值和获取的两种常见方法
1.路由传值 this.$router.push() (1) 路由跳转使用router.push()方法,这个方法会向history栈添加一个新纪录,所以,当用户点击浏览器后退按钮时,会回到之前的 ...
随机推荐
- 20145220韩旭飞《网络对抗》Exp2 后门原理与实践
20145220韩旭飞<网络对抗>Exp2 后门原理与实践 常用后门工具实践 Windows获得Linux Shell 在Windows下,先使用ipconfig指令查看本机IP: 使用n ...
- MySQL中datetime和timestamp的区别及使用
MySQL中有关TIMESTAMP和DATETIME的总结 转载自iVictor,原文链接:http://www.cnblogs.com/ivictor/p/5028368.html 一.MySQL中 ...
- hdu 6180 Schedule
Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...
- UVa 1605 联合国大楼
https://vjudge.net/problem/UVA-1605 题意:有n个国家,要求设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的. 思路: ...
- UVa 1601 万圣节后的早晨
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- hdu 5586 Sum 基础dp
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem Desc ...
- python 将列表中的字符串转为数字
本文实例讲述了Python中列表元素转为数字的方法.分享给大家供大家参考,具体如下: 有一个数字字符的列表: numbers = ['1', '5', '10', '8'] 想要把每个元素转换为数字: ...
- Hadoop 部分截图
- C# 二进制图片串互转
C# byte数组与Image的相互转换 功能需求: 1.把一张图片(png bmp jpeg bmp gif)转换为byte数组存放到数据库. 2.把从数据库读取的byte数组转换为Image对 ...
- 解决MVC 时间序列化的方法
1.全局处理 处理代码 publict static void SetSerializationJsonFormat(HttpConfiguration config) { // Web API co ...