vue之编程式导航
导航到另一个页面
<template> <div> <h3>MyHome 组件</h3> <button type="button" class="btn btn-primary" @click="goToMovie(3)">导航到Movie页面</button> </div> </template> <script> export default { name: 'MyHome', methods: { goToMovie(id) { this.$router.push('/movie/' + id) }, }, } </script> <style lang="less" scoped></style>
后退到前一个页面
<template> <div> <h3>MyMovie 组件 --- {{ $route.params.mid }} --- {{ mid }}</h3> <button type="button" class="btn btn-danger" @click="goBack">后退</button> </div> </template> <script> export default { name: 'MyMovie', props: ['mid'], methods: { goBack() { this.$router.go(-1) }, }, } </script> <style lang="less" scoped></style>