关于javascript:如何在-Spartacus-使用-UserAccountFacade-在语言设置更改后重新读取用户数据

2次阅读

共计 1543 个字符,预计需要花费 4 分钟才能阅读完成。

问题 1:如何在 Spartacus 应用 UserAccountFacade 在语言设置更改后从新读取用户数据

能够扩大上图这个 Observable.

而后应用 combineLatest 和其余的 Observable 进行组合。

问题 2:应用 outlet 时遇到谬误音讯:Type before is not assignable to type OutletPosition

解决方案:

add outletPosition = OutletPosition; to the component,

HTML 里增加代码:

[cxOutletPos]="outletPosition.BEFORE"

还须要查看:

did you add the outlets to the app component html?

例如增加如下代码到 Component HTML:

<outlets></outlets>

问题 2:HTTP 400 和 404

对于 product 明细页面来说,轻易输出一个不存在的 url,返回值为 HTTP 400:

https://cloudapp.azure.com:9002/occ/v2/electronics-spa/cms/pages?pageType=CategoryPage&code=5781122&lang=en&curr=USD

谬误音讯:

{
   "errors" : [ {
      "message" : "The value provided is not allowed.",
      "reason" : "invalid",
      "subject" : "code",
      "subjectType" : "parameter",
      "type" : "ValidationError"
   } ]
}

如果是 content page 申请不存在:

https://cloudapp.azure.com:9002/occ/v2/electronics-spa/cms/pages?pageType=ContentPage&pageLabelOrId=%2Ftest&lang=en&curr=USD

返回谬误音讯:

   "errors" : [ {
      "message" : "No content page found matching the provided label or id: /test",
      "type" : "CMSItemNotFoundError"
   } ]
}

客户能够应用自定义的 renderKeyResolver 来动静决定哪个页面应该应用哪种渲染策略,SSR 还是 CSR.

如果特定键短少翻译,则生产模式下的店面会显示不间断的空格字符。为了更容易捕获失落的键,在开发模式下,Spartacus 会显示翻译键,后面有块的名称和冒号(例如,[common:form.confirm])。

如果短少翻译,为了提供更好的用户体验,开发人员能够指定备用语言。设置 fallbackLang 选项可确保对于每个缺失的翻译,应用来自备用语言的等价物。

以下是应用英语作为备用语言的示例配置:

import {translations, translationChunksConfig} from '@spartacus/assets';

// ...

providers: [
  provideConfig({
    i18n: {
      resources: translations,
      chunks: translationChunksConfig,
      fallbackLang: 'en',
    },
  }),
];

翻译由语言和命名块形成,因而开发人员能够仅为以后语言和以后页面加载翻译资源。以下是翻译资源的构造示例:

interface TranslationResources {[lang: string]: {[chunkName: string]: {[key: string]: any; // value or nested object with keys
    };
  };
}

正文完
 0