---- AI试用 ---域名问题某些图片和js资源无法访问,导致一些代码实例无法运行!(代码里gzui.net换成momen.vip即可)

Vue监听路由 从哪个页面跳转过来的 进行后续相关操作

前端开发 蚂蚁 645℃ 0评论
<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(_"created",this.fromPage);
  },
  mounted() {
    let _this = this;
    console.log(_this.fromPage,"mounted");
    if ( _this.fromPage=="/home") { 
      window.location.href = "https://www.baidu.com"; // 跳转对应地址
    } else { 
      _this.$router.push({name: "HomeIndex"});
    }
  },
  beforeRouteEnter(to, from, next) {
    console.log( 'beforeRouteEnter',from);
    next(vm => {
      // vm相当于上面的this
      vm.fromPage = from.path;
    });
  },
  methods: {}
};
</script>

<style lang="less" scoped></style>

转载请注明:有爱前端 » Vue监听路由 从哪个页面跳转过来的 进行后续相关操作

喜欢 (0)or分享 (0)