【问题标题】:JS / GraphQL View - BigCommerce Master SKUJS / GraphQL 视图 - BigCommerce 主 SKU
【发布时间】:2021-01-17 06:37:09
【问题描述】:

使用把手将 BigCommerce 的主 SKU 输出到前端视图的最佳方式是什么。

我使用过 GraphQL,但响应速度太慢而无法使用,因为它确实需要能够在渲染时输出。任何想法将不胜感激。

GraphQL 代码

        <script type="text/javascript">
            fetch('/graphql', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Authorization': 'Bearer {{ settings.storefront_api.token }}'
                },
                body: JSON.stringify({query: `
                    query {
                        site {
                            product(entityId: {{ product.id }}) {
                                sku
                            }
                        }
                    }
                `})
            }).then(function(response) {
                return response.json();
            }).then(function(response) {
                console.log(response.data.site.product.sku);
            });
        </script>

【问题讨论】:

  • HB?作为阿贾克斯?更新? ... 那些天???使用无头(BE/API 作为数据源),前端更加分离 - 使用现代 FE ...反应或预渲染 gatsby

标签: javascript graphql handlebars.js bigcommerce graphql-js


【解决方案1】:

如果您在产品页面上:

{{product.sku}}

如果您在类别页面上:

{{#each products}}
   {{sku}
{{/each}}

您可以调试每个页面可用的上下文以了解 Stencil CLI 中可用的数据:

https://developer.bigcommerce.com/theme-objects#viewing-a-pages-context

【讨论】:

    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多