Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client获取controller数据 #211

Open
liuchamp opened this issue Jan 11, 2020 · 2 comments
Open

client获取controller数据 #211

liuchamp opened this issue Jan 11, 2020 · 2 comments

Comments

@liuchamp
Copy link

页面获取controller数据使用http,还是?

@njugray
Copy link
Contributor

njugray commented Jan 14, 2020

构造store注入到html内联script里或者提供http接口异步获取

@Gorden-Wang
Copy link

controller:

const renderData = {
  tplData,
  ssrVo: { daily, refList, wxData },
};
await ctx.ssr('/server/contentDaily/index.jsx', renderData);

index.jsx:

static async getStore({ ssrVo }) {
    const initState = {
      ...initialAppState,
      contentDaily: ssrVo,
    };
    return configureStore(initState);
  }

layout.jsx

<script
  dangerouslySetInnerHTML={{
  __html: `window.__INITIAL_STATE__ = ${state};window.__path__="${path}";`,
  }}
/>

或者不用redux也ok。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants