如何将本地路径重定向到另一个带有params Nuxt Js的页面

您好,我有一些问题,我想将url中的参数推送到NuxtJs中的另一个页面

props: {
    idPending: {
      type: Number,
      required: true
    }
},

methods: {
    fetchpage() {
      const orderId = this.idPending;
      this.$router.push(
        this.localePath({
          name: 'Checkout-Confirmation-orderId', // page with params orderId
          params: { orderId: orderId }
        })
      );
    }
  }

当我这样做时,我出现此错误,我不明白为什么

Argument type {name: string, params: {orderId: Number}} is not assignable to parameter type RawLocation   Type Number is not assignable to type string 

请帮忙谢谢您


解决方案

此错误实际上非常不言而喻,此处您只能使用String类型。
可在此处找到确认:https://github.com/vuejs/vue-router/issues/2895#issuecomment-523549070

您可以使用String(orderId),在我看来它可能更快,但主要是更安全,因为在orderId为NULL或未定义的情况下,它不会产生任何错误。

相关文章