美文网首页
(十一)利用指令控制路由

(十一)利用指令控制路由

作者: 我拥抱着我的未来 | 来源:发表于2018-02-18 09:43 被阅读0次

    本节知识点

    • 利用指令来做到页面跳转

    this.$router.go(-1) 和this.$router.go(1)

    • 首先我们先在app.vue里面增加一个按钮,绑定一个事件
    <button @click="add"></button>
    
    • 然后在app.vue里面 写入add方法
    <script>
    export default {
      name:"app",
    data(){
      return {
         message:"Hello"
       }
    },
    methods:{
       add:function(){
        this.$router.go(-1)
                   }
    }
    }
    </script>
    

    备注this.$router.go(-1)就是后退到上一个 this.$router.go(1)就是前进

    this.$router.push('/xxx') 跳转到指定的页面

    • 先写一个按钮实现跳转
    <button @click="gowhere"></button>
    
    • 然后在script里面写代码
    <script>
    export default {
      name:"app",
    data(){
      return {
         message:"Hello"
       }
    },
    methods:{
       gowhere:function(){
        this.$router.push("/xxx")
                   }
    }
    }
    </script>
    

    相关文章

      网友评论

          本文标题:(十一)利用指令控制路由

          本文链接:https://www.haomeiwen.com/subject/abovtftx.html