Vue 2
1. 传递路径参数
methods: {
navigateToUser(userId) {
this.$router.push({ path: '/user', query: { id: userId } });
}
}
2.在目标组件中获取查询参数
mounted() {
console.log(this.$route.query.id); // 获取查询参数 id
}
Vue 3
1. 传递路径参数
<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
const jump = () => {
router.push({
path: '/exm/nestRoutor',
query: {
id: '12312321'
}
})
}
</<script>
2.在目标组件中获取查询参数
<script setup>
import { useRoute} from 'vue-router'
const route = useRoute()
console.log(route.query.id);
</<script>