Vue监听路由 从哪个页面跳转过来的 进行后续相关操作
<template><div><div class="loading-box"><van-loading size="24px" color="#0094ff">加载中....</van-loading></div></div></template><script>export defaul
·
<template>
<div>
<div class="loading-box">
<van-loading size="24px" color="#0094ff">加载中....</van-loading>
</div>
</div>
</template>
<script>
export default {
data() {
return {
fromPage: "",
};
},
created() {
let _this = this;
console.log(_this.fromPage,"created");
},
mounted() {
let _this = this;
console.log(_this.fromPage,"mounted");
if ("/home" === _this.fromPage) {
window.location.href = "https://www.baidu.com"; // 跳转对应地址
} else {
_this.$router.push({name: "HomeIndex"});
}
},
beforeRouteEnter(to, from, next) {
console.log(from, 'beforeRouteEnter');
next(vm => {
// vm相当于上面的this
vm.fromPage = from.path;
});
},
methods: {}
};
</script>
<style lang="less" scoped></style>
更多推荐
已为社区贡献1条内容
所有评论(0)