vue之命名路由

router.js

{ name: 'mov', path: '/movie/:mid', component: Movie, props: true },

home.vue

<template>
  <div>
    <h3>MyHome 组件</h3>
    <router-link :to="{ name: 'mov', params: { mid: 2 } }">go to movie</router-link>
    <button type="button" class="btn btn-primary" @click="goToMovie(1)">go to movie</button>
  </div>
</template>

<script>
export default {
  name: 'MyHome',
  methods: {
    goToMovie(id) {
      this.$router.push({
        name: 'mov',
        params: {
          mid: id,
        },
      })
    },
  },
}
</script>

<style lang="less" scoped></style>

 

posted @ 2022-06-08 14:17  hi123hi159  阅读(49)  评论(0)    收藏  举报