vue2
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26methods: { ...mapActions('userModule', { userRegister: 'register' }), validateState(name) { // 这里是es6 解构赋值 const { $dirty, $error } = this.$v.user[name]; return $dirty ? !$error : null; }, register() { // 验证数据 this.$v.user.$touch(); if (this.$v.user.$anyError) { return; } // 请求 this.userRegister(this.user).then(() => { // 跳转主页 this.$router.replace({ name: 'Home' }); }).catch((err) => { this.$bvToast.toast(err.response.data.msg, { title: '数据验证错误', variant: 'danger', solid: true, }); }); },
vue3
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13methods: { ...mapActions('userModule', { register: 'register' }), onSubmit(values: any) { this.register(values).then((res) => { if (res.data.code === 200) { router.replace({ name: 'Home' }); } }).catch((err) => { Notify({ type: 'warning', message: err.response.data.msg }); }); }, },
总结:
vue2使用:this.$router.replace({ name: ‘Home’ });
vue3使用:router.replace({ name: ‘Home’ });
最后
以上就是温柔楼房最近收集整理的关于vue2和vue3使用 router.replace({ name: ‘Home‘ });的全部内容,更多相关vue2和vue3使用内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复