beidou
beidou copied to clipboard
client获取controller数据
页面获取controller数据使用http,还是?
构造store注入到html内联script里或者提供http接口异步获取
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。