我有一些陣營代碼字符串中,例如:渲染從字符串陣營組件
const component = `
function App() {
return (
<div>
test
</div>
);
}
`;
而且我希望能夠呈現該組件從瀏覽器中,是這樣的:
import React, { Component } from 'react';
import { render } from 'react-dom';
import * as babel from 'babel-standalone';
const babelCode = babel.transform(component, { presets: ['react', 'es2015'] }).code;
render(eval(babelCode), document.getElementById('WorkFlow'));
這個特殊的例子不起作用,但它顯示了我在找什麼,感謝任何幫助!
謝謝!
哇,這真的有用,謝謝! –
只有一件事,實際上它的工作原理是這樣,但我們應該在'Function'類之前輸入'new' –
糟糕!是的,我更新了答案! –