首页 > 其他 > 详细

VUE项目实现页面跳转

时间:2019-04-17 16:08:07      阅读:133      评论:0      收藏:0      [点我收藏+]
打开一个VUE项目,目录结构是这样的:
技术分享图片

 



如现在有两个页面aaa和HelloWorld,路由配置在index.js中:

    import Vue from ‘vue‘
    import Router from ‘vue-router‘
    import HelloWorld from ‘@/components/HelloWorld‘
    import aaa from ‘@/components/aaa‘
     
    Vue.use(Router)
     
    export default new Router({
      routes: [
        {
          path: ‘/‘,
          name: ‘HelloWorld‘,
          component: HelloWorld
        },
        {
            path: ‘/aaa‘,
          name: ‘aaa‘,
          component: aaa
        }
      ]
    })

现在在HelloWorld中点击按钮跳转到aaa,在aaa中点击按钮也可以返回到HelloWorld:

1、HelloWorld:

    <div class="hello">
        <h1>{{ msg }}</h1>
        <button @click="go">点我跳转</button>
    </div>

    <script>
    export default {
      name: ‘HelloWorld‘,
      data () {
        return {
          msg: ‘哈哈‘
        }
      },
      methods:{
          go(){
              this.$router.push(‘/aaa‘)
          }
      }
    }
    </script>

2、aaa:

    <template>
        <div>我是aaa
        <button @click="back">点我返回</button>
        </div>
        
    </template>
     
    <script>
    export default {
      name: ‘aaa‘,
      /*data () {
        return {
          msg: ‘哈哈‘
        }
      },*/
      methods:{
          back(){
              this.$router.push(‘/‘)
          }
      }
    }
    </script>

 

VUE项目实现页面跳转

原文:https://www.cnblogs.com/Free-Thinker/p/10724053.html

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