Vue 店面:如何覆盖助手内的功能?

问题描述

我需要修改vuestorefront/core/modules/catalog/helpers/search.ts下的'preConfigureProduct'函数

https://github.com/vuestorefront/vue-storefront/blob/hotfix/v1.12.3/core/modules/catalog/helpers/search.ts#L51

我需要根据客户要求进行定制。因此我需要在我的项目中覆盖这个函数。 但是没有关于如何从 helper 覆盖一个函数的文档。我也是 vue 店面的新手,所以我不完全了解模块扩展或混合。

提前致谢。

解决方法

我自己想通了,我也会为谁被卡住留下一个简短的答案。 此外,我不确定这是一个好的做法,如果您知道更好的方法,请将其保留在这里。

据我所知,如果您需要覆盖 helper 中的一个函数,您还需要“覆盖”调用您的 helper 函数的函数。

就我而言,我需要从模块目录助手中覆盖函数 preConfigureProduct 。

调用这个 preConfigureProduct 的函数是模块目录中的一个 asyc 函数 configureProducts-next,https://github.com/vuestorefront/vue-storefront/blob/hotfix/v1.12.3/core/modules/catalog-next/store/category/deprecatedActions.ts#L22。 (我知道它是 deprecatedActions。我的下一个工作是弄清楚如何切换到新的)

因此,我扩展了模块目录-next,并逐字复制粘贴 configureProducts(因为我不需要修改它),但从我的新文件中导入 preConfigureProduct。

import { preConfigureProduct } from './helpers/search'

我的新 search.ts 文件:

import Vue from 'vue';
import config from 'config';

export const preConfigureProduct = ({ product,populateRequestCacheTags }) => {
    .....
  return product;
};

就是这样!

希望它可以帮助其他人。 如有错误,欢迎指出。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...