Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

script标签修改了type为text/babel,但刷新网页还是显示text/javascript

刚开始接触react,想在网站上使用,但在html页面中引入reactjs文件时总是不起作用,并报错:Uncaught SyntaxError: Unexpected token '<'

上网查了好多,说是需要在引入的script标签中设置type为"text/babel",按照网上说的更改了,但依然报同样的错误,引入的关键代码如下:

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel" src="/source/plugin/fr_ticket/template/t2babel.js"></script>

但网页显示:
image.png

reactjs代码如下:

ReactDOM.render(
    <h1>Hello, world!</h1>,
    document.getElementById('root')
);

不知道哪里出了问题,希望各位前辈大佬能帮忙看一下,蟹蟹啦!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script src="./source/plugin/fr_ticket/template/t2babel.js"></script>
<script type="text/babel">
ReactDOM.render(
    <h1>Hello, world!</h1>,
    document.getElementById('root')
);
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...