可以使用 '$route.params.id' 来获取动态路由中的 id 值。例如:

<template>
  <div>
    <p>{{ $route.params.id }}</p>
  </div>
</template>

<script>
export default {
  mounted() {
    console.log(this.$route.params.id);
  }
}
</script>

在模板中使用 {{ $route.params.id }} 来显示 id 值,在 mounted 钩子函数中使用 this.$route.params.id 来获取 id 值。

Vue.js 动态路由中获取 ID 值的教程

原文地址: https://www.cveoy.top/t/topic/m346 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录