VUE的hash路由模式

router-view标签就是确定路由位置的 一般放置在APP.vue文件里

路由位置

image-20201208152415017

vue-router

路由模式分为三种 hash history abstract

hash路由就是: 跳转的位置是#加上后面的字符

类似于

image-20201208153802590

可以通过控制台location.hash查看当前hash是多少

image-20201208153937571

** 路由的使用**

在App中设置

<!-- 用于存放路径的组件-->
<router-view></router-view>

image-20201208160331160

然后在router/index.js 中添加需要的VUE模板页面

import Vue from 'vue'
import Router from 'vue-router'
import LandingPage from "../components/LandingPage";
import index from "vuex";
import VueRouter from "vue-router";

//注册插件作为VUE的属性
Vue.use(Router,VueRouter)

export default new Router({
  mode: 'hash',
  routes: [ //前端路由 配置的地方
    {
      path: '/',                //访问跳转地址
      name: 'landing-page',     //名字
      component: LandingPage    //实际文件地址
    },{
      path: '/index',
      name: 'index',
      component: ()=> import('../components/LandingPage/index')
    },
    {
      path: '*',
      redirect: '/'
    }
  ]
})

设置主页面LandingPage.vue

<template>
  <div id="app">
    <el-container>
      <el-header>
        <el-row>
          <el-button type="primary" round @click="navRouter()">左边看美女</el-button>
          <el-button disabled >这是主页面</el-button>
          <el-button type="primary" round @click="systemRouter()">右边有迪迦</el-button>
        </el-row>
      </el-header>
      <el-main>

      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  methods: {
    navRouter() {
      this.$router.push("/index")
    },
    systemRouter(){
      this.$router.push("/system")
    }
  }
}
</script>

<style>
.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 850px;
}
</style>

LandingPage/index.vue中设置返回

<template>
  <div id="app">
    <el-container>
      <el-header>
        <el-row>
          <el-button >左边看美女</el-button>
          <el-button type="primary" round @click="navRouter()" >这是主页面</el-button>
          <el-button type="primary" round @click="systemRouter()">右边有迪迦</el-button>
        </el-row>
      </el-header>
      <el-main>
        <P>这里是美女</P>
      </el-main>
    </el-container>
  </div>
</template>

<script>
export default {
  methods: {
    navRouter() {
      this.$router.push("/")
    },
    systemRouter(){
      this.$router.push("/system")
    }
  }
}
</script>

<style>
.el-header, .el-footer {
  background-color: #B3C0D1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
.el-main{
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 850px;
}
</style>

基本实现跳转

image-20201208170107172

image-20201208170113499

可以实现来回跳转

emm 基于electron VUE 和elementui的路由跳转页面就完成了

img

(img-SECh62fA-1607479301124)]

[外链图片转存中…(img-NE2jylM6-1607479301125)]

可以实现来回跳转

emm 基于electron VUE 和elementui的路由跳转页面就完成了

[外链图片转存中…(img-kBTjQIQy-1607479301127)]

通过控制台看出来这是hash的跳转 另外两种 后面有时间再学习

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值