通过代码跳转路由
<template> <div id="app"> <button @click="toHome">首页</button> <button @click="toAbout">关于</button> <!-- 相当于占位符 --> <router-view></router-view> </div> </template> <script> export default { name: 'App', methods:{ toHome(){ this.$router.push('/home') //地址不能前进后退 //this.$router.replace('/home') }, toAbout(){ this.$router.push('/about') //this.$router.replace('/about') } } } </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>