目录
1. 普通跳转
setTimeout(function () {
//实现方法
}, 1500);
2. 跳转路由
在里面,不能直接写this.$router/push("/") ,会报错,
解决方法:先在外层定义,let that=this;然后在里面使用that
async SaveData(param) {
let that = this;
let resultdatas = {
code: 200,
msg: "保存成功,即将跳转到首页",
};
if (resultdatas.code === 200) {
Message.success({
message: resultdatas.msg,
});
//过几秒执行
setTimeout(function () {
that.$router.push("/mainIndex");
}, 1500);
} else {
Notification.error({
title: "提示",
message: resultdatas.msg,
offset: 50,
});
}

文章介绍了在Vue.js应用中进行页面跳转的两种方式:普通跳转和基于路由的跳转。在处理路由跳转时,由于异步操作中this的指向问题,需要在外层保存this引用,然后在setTimeout内部使用that来调用$router.push方法进行页面切换。如果保存数据成功,页面将在1.5秒后跳转到/mainIndex,否则显示错误通知。

894

被折叠的 条评论
为什么被折叠?



