zoukankan      html  css  js  c++  java
  • vue路由实例

    router.js:

    import Vue from 'vue'
    import Router from 'vue-router'
    import Home from '@/components/Home'
    import HelloWorld from '@/components/HelloWorld'
    Vue.use(Router)
    export default new Router({
      routes: [
      {
        path: '/Home',
        component: Home
      },
      {
        path: '/HelloWorld',
        component: HelloWorld
      },
      {
        path: '/',
        redirect: '/Home'
      }
      ]
    })
    import Vue from 'vue'
    import Router from 'vue-router'
    import Home from '@/components/Home'
    Vue.use(Router)
    export default new Router({
      routes: [
      {
        path: '/Home',
        component: Home
      },
      {
        path: '/HelloWorld',
        component: () => import('./views/HelloWorld')
      },
      {
        path: '/',
        redirect: '/Home'
      }
      ]
    })

    App.vue:

    <template>
      <div id="app">
      <headnav></headnav>
      <router-view></router-view>
      <p @click="addLink">链接</p> </div> </template> <script> import HeadNav from './components/HeadNav' export default {   name: 'App',   data () {    return {    }   },   components: {    'headnav' : HeadNav   },
      methods:{
        //点击加链接
        addLink(){
          
    this.$router.push({
            path: '/Home',
             params: {data: this.drafe}
           });
        }
      } }
    </script>

      HeadNav.vue:

    <template>
      <div>
      <router-link to="/">Home</router-link>
      <router-link to="/HelloWorld">HelloWorld</router-link>
      </div>
    </template>
  • 相关阅读:
    笛卡尔树学习笔记
    图论基础(自认为很全)
    我的博客在这里
    C++学习资料
    test
    个人介绍
    CF1153F Serval and Bonus Problem
    【ZJOI2020】抽卡
    【LOJ】小 Q 的序列
    我的个人博客:https://xyix.github.io
  • 原文地址:https://www.cnblogs.com/shirliey/p/9674644.html
Copyright © 2011-2022 走看看