beidou icon indicating copy to clipboard operation
beidou copied to clipboard

client获取controller数据

Open liuchamp opened this issue 5 years ago • 2 comments

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

liuchamp avatar Jan 11 '20 20:01 liuchamp

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

njugray avatar Jan 14 '20 01:01 njugray

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。

Gorden-Wang avatar Jan 14 '20 02:01 Gorden-Wang