You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Shopify的discount.js中强制重载并清除函数缓存数据?

Shopify discount.js 页面重载重置值问题

我已经折腾好几天了,目标是实现页面重载时清除部分函数中之前设置的值,但在Shopify的discount.js里试了各种方法都没效果。

我试过在页面加载完成时清除缓存并调用重置价格的oldPrice()函数,代码如下,但完全没用:

document.addEventListener('DOMContentLoaded', () => {
    // Clean local cache when loading
    sessionStorage.clear();
    localStorage.clear();

    // Call oldPrice to reset prices
    oldPrice();
});

但如果通过点击事件触发location.reload()再调用oldPrice(),却能正常生效:

coupon_tag.addEventListener('click', () => {
    location.reload();
    oldPrice();
});

内容的提问来源于stack exchange,提问作者Andrew Gabriel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 09:39:51