小编Abr*_*ngh的帖子

intl.formatMessage不工作 - react-intl

我正在尝试使用语言翻译react-intl.当我使用它时<FormattedMessage id='importantNews' />,它是完美的.但是,当我使用以下代码时intl.formatMessage(),它不起作用并抛出一些错误.我不知道它有什么问题.

import { injectIntl, FormattedMessage } from 'react-intl';

function HelloWorld(props) {
  const { intl } = props;
  const x = intl.formatMessage('hello') + ' ' + intl.formatMessage('world'); //not working
  const y = <FormattedMessage id='hello' />; //working
  return (
    <button>{x}</button>
  );
}

export default injectIntl(HelloWorld);
Run Code Online (Sandbox Code Playgroud)

我的根组件是这样的,

import ReactDOM from 'react-dom';
import { addLocaleData, IntlProvider } from 'react-intl';
import enLocaleData from 'react-intl/locale-data/en';
import taLocaleData from 'react-intl/locale-data/ta';

import HelloWorld from './hello-world';

addLocaleData([
  ...enLocaleData,
  ...taLocaleData
]);

const …
Run Code Online (Sandbox Code Playgroud)

reactjs redux react-intl react-redux babel-plugin-react-intl

8
推荐指数
1
解决办法
1万
查看次数

在 Ember 中使用多个 yields 在不同的地方显示页眉、正文、页脚

如何在 Ember 中使用多个产量在不同的地方显示页眉、正文、页脚?在下面添加了示例代码以供参考。但不工作并抛出错误说,

断言失败:找不到名为“ib.footer”的助手

components/common/info-bar-footer.hbs:

{{yield}}
Run Code Online (Sandbox Code Playgroud)

components/common/info-bar-header.hbs:

{{yield}}
Run Code Online (Sandbox Code Playgroud)

components/common/info-bar.hbs:

<div class="info-bar" style="display: {{if isopen 'block' 'none'}}">
    <div class="info-bar-header">
        <button class="btn-close" data-dismiss="info-bar" {{action "handleCloseInfoBar"}}>x</button>
        {{yield (hash header=(component "common/info-bar-header"))}}
    </div>
    <div class="info-bar-footer">
        {{yield (hash footer=(component "common/info-bar-footer"))}}
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

模板/home.hbs:

{{#common/info-bar isopen=true as |ib|}}
    {{#ib.header}}
        <p class="info-content">
            Hello, nice to see you again
        </p>
    {{/ib.header}}
    {{#ib.footer}}
        <button class="btn-default">Ok</button>
    {{/ib.footer}}
{{/common/info-bar}}
Run Code Online (Sandbox Code Playgroud)

handlebars.js ember.js

4
推荐指数
1
解决办法
644
查看次数