vue.js this.$router.push无效解决
来源:互联网 发布:淘宝运营vip课程 云盘 编辑:程序博客网 时间:2024/05/16 03:00
login() { if(this.email.length > 0 && this.password.length >0) { this.$http.post('/api/login', { user: this.email, password: this.password }) .then(res => { let userPwd = res.data if(this.password == userPwd) { this.$router.push("/") } else { alert("错误,请重新输入!") } }) .catch(err => { console.log(err) }) } else { alert("输入错误!") } }
this.$router.push(“/”)不是跳转到主页,而是变成这样:http://127.0.0.1:8080/login?email=yejia%40qq.com&password=123456,请问哪里错啦?
解决方案1:
有没有可能是已经跳转了,但是主页判断成了没有登录,然后又跳回来了。
解决方案2:
你这里的 this指向已经不是 vue 的对象啦,可以这么改
login() { const self = this; if(this.email.length > 0 && this.password.length >0) { this.$http.post('/api/login', { user: this.email, password: this.password }) .then(res => { let userPwd = res.data if(this.password == userPwd) { self.$router.push("/") } else { alert("错误,请重新输入!") } }) .catch(err => { console.log(err) }) } else { alert("输入错误!") } }
阅读全文
0 0
- vue.js this.$router.push无效解决
- Vue中this.$router.push参数获取
- Vue中this.$router.push参数获取
- vue-router同一路由地址同页面切换无效解决
- vue-router 2.0 跳转之router.push()
- vue-router 2.0 常用基础知识点之router.push()
- vue-router 2.0 常用基础知识点之router.push()
- vue-router 2.0 常用基础知识点之router.push()
- vue-router 2.0 常用基础知识点之router.push()
- vue-router 2.0 常用基础知识点之router.push()
- vue-router.js,入门案例
- vue.js router的配置
- vue.js——router
- Vue.js笔记-vue-router入门
- vue2.0中.vue文件页面跳转之.$router.push
- vue.js+vue-router+sea.js构建SPA应用
- 关于vue-router.js 下载的问题
- 在Weex中,使用vue-router 跳转无效
- 【XSY1599】dices 期望DP
- mySQL第一步,导入导出现有数据库文件
- hadoop eclipse 导出jar
- SortMap使用
- 西安赛区 sum
- vue.js this.$router.push无效解决
- 在结构体中定义char data[0]的用法
- sprig学习笔记十九 事务的传播行为
- C语言标量类型
- more effective C++效率解析
- Java面试题全集(中)
- 面试题(7)
- 1031 字符串打印
- 日期选择框架