码迷,mamicode.com
首页 > 其他好文 > 详细

使用element框架 增加router路由

时间:2020-07-01 14:21:10      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:loading   class   route   temp   div   assets   lin   -o   cal   

技术图片

 

 

第一个小程序 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路由

标签:loading   class   route   temp   div   assets   lin   -o   cal   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!