NUXT3-VUE中的用户oute和userOuter有什么区别

发布于 2025-02-12 10:39:58 字数 911 浏览 0 评论 0 原文

我想了解,

const Route = useRoute()

有什么

const Router = useRouter()

nuxt3/vue中

区别。另外,我无法正确使用路由器。

提交时,我想使用使用查询字符串的另一页。

<template>
  <button @click="SearchTaxi"></button>
</template>

<script setup>
import { ref } from 'vue'
const router = useRouter()
const pickuppoint = ref('')
const dropoffpoint = ref('')

const SearchTaxi = () => {
router.push({
  path: `/airport-transfers/results?pickuppoint=${pickuppoint.value}&dropoffpoint=${dropoffpoint.value}`})
}
</script>

我希望途径会改变,

"url/airport-transfers/results?pickuppoint=XXXX&dropoffpoint=XXXX"

但我会得到

"url/airport-transfers/results"

I want to understand, what is the difference between

const Route = useRoute()

and

const Router = useRouter()

in Nuxt3/Vue.

Also, I am not able to use router properly.

on submit, I want to push to another page with query strings using.

<template>
  <button @click="SearchTaxi"></button>
</template>

<script setup>
import { ref } from 'vue'
const router = useRouter()
const pickuppoint = ref('')
const dropoffpoint = ref('')

const SearchTaxi = () => {
router.push({
  path: `/airport-transfers/results?pickuppoint=${pickuppoint.value}&dropoffpoint=${dropoffpoint.value}`})
}
</script>

I expect route to change to

"url/airport-transfers/results?pickuppoint=XXXX&dropoffpoint=XXXX"

but i am getting

"url/airport-transfers/results"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-02-19 10:39:59

有两件事:

  • 路由,其中​​包含与路径,主机名,当前查询参数等相关的所有信息...
  • 路由器,将为您提供所有功能的实际VUE路由器,例如客户端端导航(使用按下替换),回滚到 n-1 ,解决等...

您可以检查API: https://router.vuejs.org/api/api/

并查看其中每个方法都有哪些方法/字段。

如果要推出一些查询参数和新路径,则可以使用以下内容

router.push({
  path: '/airport-transfers/results',
  query: { 
    pickuppoint: pickuppoint.value,
    dropoffpoint: dropoffpoint.value
  }
})

,如下所述: https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-a-different-location

There are 2 things:

  • route, which will contain all the info related to the path, hostname, current query params etc...
  • router, the actual Vue router that will provide you all the features such as a client side navigation (with push or replace), rollback to the n-1, resolve etc...

You can check the API: https://router.vuejs.org/api/
And see which methods/fields are available on each one of them.

If you want to push some query params and a new path, you could use the following

router.push({
  path: '/airport-transfers/results',
  query: { 
    pickuppoint: pickuppoint.value,
    dropoffpoint: dropoffpoint.value
  }
})

As explained here: https://router.vuejs.org/guide/essentials/navigation.html#navigate-to-a-different-location

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文