How to make script type both text/babel and module?

后端 未结 4 866
遥遥无期
遥遥无期 2021-02-07 06:59

It works perfectly because I haven\'t included JSX, but when I replace the script type with text/babel, it doesn\'t work because the module fails to load. bro

4条回答
  •  面向向阳花
    2021-02-07 07:10

    you may prefer to use an alias to createElement. This way is faster for the engine. For example use h or e.

    const { createElement: h } = React;
    
    const App = () => {
       return h('div', {}, 'hello!!'); 
    }
    

    Otherwise, it is possible to use @babel/standalone module, please see more on here https://babeljs.io/docs/en/next/babel-standalone.html.

提交回复
热议问题