首页 > 其他 > 详细

使用element框架 增加router路由

时间:2020-07-01 14:30:15      阅读:48      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 

第一个小程序 router-link-路由的跳转

技术分享图片
<template>
    <div id="app">

        <div>hello world!</div>
        <router-view></router-view>

    </div>
</template>

<script>
    export default {
        name: App
    }
</script>
App.vue

 

技术分享图片
import Vue from ‘vue‘
import Router from ‘vue-router‘
// import Hello from "@/components/Hello";

Vue.use(Router)

export default new Router({
    routes: [
        {
            path: ‘/‘,
        },
        {
            path: ‘/hello‘,
            name: ‘Hello‘,
            // component: Hello // 上下两种写法都ok,下面这种使用的是懒加载
            component: () =>
                import(/* webpackChunkName: "download" */ ‘@/components/Hello.vue‘)
        }
    ]
})
router.js

 

技术分享图片
<template>
    <div>
        <h1>hello router!</h1>
    </div>
</template>

<script>
    export default {
        name: "Hello"
    }
</script>

<style scoped>

</style>
Hello.vue

 

注:这里有个坑, vue-cli@3上面这个程序就报错

怎么回事呢,我用pycharm专业版的,安装了一个VUE

写这样的程序就报错了,至于为啥我也不知道,还有个报错,同样的代码放到2.13版本就一点问题也没有

技术分享图片

 编程式导航,也可以理解为函数里面设置跳转

<template>
  <div id="app">
    <img src="./assets/logo.png">
<!--    <router-link to="/test">aaa</router-link>-->
    <button @click="toTest">跳转按钮</button>
    <router-view/>
  </div>
</template>

<script>
export default {
  name: App,
  methods:{
    toTest:function(){
      this.$router.push({path:"/test"})  // 就是这一句,注意是router,不是route
    }
  }
}
</script>

<style>
#app {
  font-family: ‘Avenir‘, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

 

使用element框架 增加router路由

原文:https://www.cnblogs.com/renfanzi/p/13218923.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!