问题描述
我正在尝试使用Vue Apollo查询单个产品,但我不明白我在做什么错。在控制台中,出现以下错误:Observable.js?a7b2:65 Uncaught TypeError: Cannot read property 'product' of undefined
查询:
export const getProduct = gql`
query getProduct ($productId: ID!) {
product (where: {id: $productId}) {
id
title
description
price
productDetails {
html
}
productAssets {
id
url
}
}
}
`;
组件:
apollo: {
$loadingKey: 'loading',products: {
query: getProduct,variables: {
$productId: 'ABC123',},result ({data}) {
this.loading = false;
this.product = data.product;
this.assets = data.assets;
},error () {
this.error = true;
this.sentryError = error;
},
如果我将ID硬编码在其中,则可以使用。
export const product = gql`
query getProduct ($product: ID!) {
product (where: {id: "ABC123"}) {
id
title
description
price
productDetails {
html
}
productAssets {
id
url
}
}
}
`;
我看不到我所缺少的东西,任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)