javascript - How to get router in vue single file component
阿神
阿神 2017-07-05 10:48:49
0
3
893
<template>
    <p>
        a.vue
        <router-link to="/a/a1">a1</router-link>
        <router-link to="/a/a2">a2</router-link>
        <br>
        <button @click="gta1()">a1</button>
        <router-view></router-view>
    </p>
</template>
<script>

    export default{
        methods:{
            gta1(){
                router.push({path:'a'}) //这里报错了, “router is not defined”
            }
        }
    }
</script>

I would like to ask, how can I obtain the router and implement programmatic navigation?

阿神
阿神

闭关修行中......

reply all(3)
扔个三星炸死你

this.$router

某草草

See component injection for details

$router: router instance.
$route: currently activated routing information object.

Peter_Zhu
 this.$router.push({path:'a'})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template