带有打字稿的 vue 没有重载匹配此调用

时间:2021-01-14 01:30:13

标签: typescript vue.js

为什么在查询的 ID 部分会出现该错误?

没有与此调用匹配的过载。

<template>
  <swiper-slide
    slot="list"
    v-for="(list, index) in list.banner"
    :key="index"
    ><img :src="list.image_url" @click="noticeRead(list.id)"
  /></swiper-slide>
</template>
export default class Main extends Vue {
noticeRead(id: number): void {
  if (id != null) {
    this.$router.push({
      path: "/help/notice/read",
      query: {
        id: id ,
      },
        });
      }
    }
}

1 个答案:

答案 0 :(得分:0)

当您在 , 参数中丢失最后一个 $router.push() 时会发生什么?

所以打字稿变成:

export default class Main extends Vue {
  noticeRead(id: number): void {
    if (id != null) {
      this.$router.push({
        path: "/help/notice/read",
        query: {
          id: id
        }
      })
    }
  }
}