zoukankan      html  css  js  c++  java
  • Uncaught SyntaxError: Inline Babel script: Adjacent JSX elements must be wrapped in an enclosing tag

    1、错误描述

    babel.min.js:7 Uncaught SyntaxError: Inline Babel script: Adjacent JSX elements must be wrapped in an enclosing tag (3:25)
      
    1 | 
      2 | 			
    function Person(info){
    > 3 | 				
    return <h1>个人信息:</h1><h3></h3>;
        | 				                     
    ^
      4 | 			}
      5 | 			
      
    6 | 			const p = <Person/>;
        
    at t.J.raise (babel.min.js:7)
    at t.ge.jsxParseElementAt (babel.min.js:8)
    at t.ge.jsxParseElement (babel.min.js:8)
    at t.parseExprAtom (babel.min.js:8)
    at te.parseExprSubscripts (babel.min.js:6)
    at te.parseMaybeUnary (babel.min.js:6) 
    at te.parseExprOps (babel.min.js:6)
    at te.parseMaybeConditional (babel.min.js:6)
    at te.parseMaybeAssign (babel.min.js:6)
    at t.parseMaybeAssign (babel.min.js:8)

    2、错误原因

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script src="../js/react.development.js"></script>
    		<script src="../js/react-dom.development.js"></script>
    		<script src="../js/babel.min.js"></script>
    	</head>
    	<body>
    		<div id="showData"></div>
    		<script type="text/babel">
    			function Person(info){
    				return <h1>个人信息:</h1><h3></h3>;
    			}
    			
    			const p = <Person/>;
    			ReactDOM.render(
    				p,
    				document.getElementById('showData')
    			);
    		</script>
    	</body>
    </html>
    

       如果在返回多个标签时,只是使用一个组件,将多个标签并列显示,会出现问题

    3、解决办法

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script src="../js/react.development.js"></script>
    		<script src="../js/react-dom.development.js"></script>
    		<script src="../js/babel.min.js"></script>
    	</head>
    	<body>
    		<div id="showData"></div>
    		<script type="text/babel">
    			function Person(info){
    				return <h1>个人信息:</h1>;
    			}
    			
    			function Pname(info){
    				return <h3>张三</h3>
    			}
    			
    			function Info(k){
    				return (
    					<div>
    					   <Person/>
    					   <Pname/>
    					</div>
    				);
    			}
    			
    			const info = <Info/>;
    			ReactDOM.render(
    				info,
    				document.getElementById('showData')
    			);
    		</script>
    	</body>
    </html>
    
  • 相关阅读:
    python爬取哦漫画
    NLP系列(2)_用朴素贝叶斯进行文本分类(上)
    svm 笔记
    nlp学习笔记
    LR
    bp网络全解读
    最小二乘法
    学习参考
    pandas中的quantile函数
    泰坦尼克号与小费与乘客数量与 鸢尾花数据集
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313718.html
Copyright © 2011-2022 走看看