typescript - Vue Ruter 4 没有重载匹配这个调用。重载 1 of 3,给出以下错误
问题描述
我在 vuex 中创建动作:
export interface Actions {
getProductsByCategory({ commit }: { commit: Commit }, slug: string): Promise<Product[]>
}
export const actions: ActionTree<State, RootState> & Actions = {
async getProductsByCategory ({ commit }, slug): Promise<Product[]> {
const products = await getProductsByCategory(slug)
commit('setProductList', products)
return products
}
}
和路线一样
{
path: '/category/:slug',
name: 'category',
component: Category,
},
我要做的最后一件事是调用名为“getProductsByCategory”的调度。为此,我使用 Onmounted Hook 制作了小组件
setup () {
const store = useStore()
const route = useRoute()
const products: Ref<Product[]> = ref([])
onMounted(async () => {
const slug = route.params.slug
products.value = await store.dispatch('getProductsByCategory', slug)
})
return {
products
}
}
但是打字稿告诉我错误
Type 'string | string[]' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.
为什么 TS 不明白 slug 是一个字符串,我该如何纠正这个问题?
解决方案
推荐阅读
- events - Electron:检测 webview 中的弹出/警报窗口
- c# - MongoDB 的单例设计模式
- c - 如何在不使用 ascii 代码的情况下在 C 中进行字符和数字之间的算术运算
- google-colaboratory - 为什么我的 google colab 不适用于我的 Google Chrome
- python - 如何从 91 个关键点生成人的 3d 模型/网格?
- windows - 为什么某些 Windows 服务器机器上的旧程序会错误地显示俄语字符串?
- bash - Bash Script:不识别大写和小写
- javascript - Next.js 仅在 Image 组件上设置点击事件
- node.js - 数据未添加到 mongodb
- ios - 如何在swift 5中滚动到tableview的底部单元格