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
425 views
in Technique[技术] by (71.8m points)

reactjs - Imported javascript file in react is not included in page, so how to solve this problem or there is any other way to do the same >?

I am working on simple react app, when i used multiple js file Myinfo.js and p2.js. when i try to import Myinfo.js in p2.js file, it doesn't working and showing me nothing on webpage.

I am using babel p2.js file and it is not showing me imported Myinfo.js in page and showing me nothing me on web page. so how to solve this problem or is there any other way to do the same >>?

here is some code..

index.html :

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
    <script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
    </head>
    <body>
    <div id="root"></div>
    <script src="pract/p2.js" type="text/babel"></script>
    </body>
    </html>

p2.js :

import Myinfo from 'components/Myinfo';

ReactDOM.render(
<Myinfo />, document.getElementById("root")
);

components/Myinfo.js :

    function Myinfo() {
    return (
        <div>
            <h1>Country</h1>
            <p>This is paragraph about country..</p>
            <ul>
                <li>India</li>
                <li>Japan</li>
                <li>Australia</li>
            </ul>
        </div>
     )}
question from:https://stackoverflow.com/questions/65901871/imported-javascript-file-in-react-is-not-included-in-page-so-how-to-solve-this

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

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

...