栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在非反应网页上渲染反应应用

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在非反应网页上渲染反应应用

有关此答案的更多背景信息,请参阅问题评论


index.html

<!DOCTYPE html><html>    <head>        <title>Example</title>        <script type="text/javascript" src="/bundle.js"></script>    </head>    <body>        <div id="content1">        </div>        <script type="text/javascript"> mount("content1", "testing")        </script>        <div id="content2">        </div>        <script type="text/javascript"> mount("content2", "more testing")        </script>    </body></html>

index.js

import React from 'react'import { render } from 'react-dom'import { createStore } from 'redux'import { Provider } from 'react-redux'import { App } from './app'window.mount = function(id, customText) {    const store = createStore((state = {}) => state)    render(        <Provider store={store}> <App text={customText} />        </Provider>,         document.getElementById(id)    )}

app.js

import React from 'react'export const App = ({ text }) => {    return (        <div>{text}</div>    )}

它仅在创建商店并将应用程序包装在中的情况下才具有redux集成

Provider
,但是我看不出任何原因无法从那里正常运行。

我使用webpack捆绑和webpack-dev-server进行了测试。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/406645.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号