第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

import 語句給出語法錯(cuò)誤,指出“無法在模塊外部使用 import 語句”

import 語句給出語法錯(cuò)誤,指出“無法在模塊外部使用 import 語句”

繁花不似錦 2022-09-02 17:19:57
我是Web開發(fā)的新手,這只是我創(chuàng)建的一個(gè)簡(jiǎn)單的代碼,用于測(cè)試我安裝的新文本編輯器,我在嘗試導(dǎo)入react時(shí)遇到了此錯(cuò)誤,因?yàn)槲矣龅搅艘恍┢渌e(cuò)誤,例如;類型錯(cuò)誤: 無法讀取未定義的屬性“createElement”請(qǐng)問,我該如何解決這個(gè)問題?導(dǎo)入語句有誤嗎?import React, { Fragment } from 'react';console.log("Testing");var document;//made this declaration because I got a document undefined error document.createElement("p"):const p = document.createElement("p")p.innerHTML = "This is to test the javascript";const body = document.querySelector("body");body.insertBefore(p,body.childNode[-1]);<!DOCTYPE html><html><head>  <title>Testing vs code</title>  <link rel="stylesheet" type="text/css" href="styles.css"/>  </head><body>  <h1>Testing the vscode html preview package</h1>  <h2>Hello</h2>  <script type="module" src="js-prac.js"></script></body></html>
查看完整描述

3 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

我知道你想用 React 創(chuàng)建一個(gè)簡(jiǎn)單的應(yīng)用程序。我建議你先讀一 https://kentcdodds.com/blog/how-to-react,然后再讀這個(gè):https://reactjs.org/tutorial/tutorial.html

可以通過在開始時(shí)導(dǎo)入腳本來創(chuàng)建 react 應(yīng)用程序,但這不是構(gòu)建 react 應(yīng)用程序的推薦方法。

完成上述帖子后,請(qǐng)?jiān)谀x擇的平臺(tái)上找到您選擇的好教程,無論是基于博客還是基于視頻。我可以舉出一些像udemy,前端大師,復(fù)數(shù)視覺,還有更多。


查看完整回答
反對(duì) 回復(fù) 2022-09-02
?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊

看看 ReactJS 網(wǎng)站。


你應(yīng)該使用 Node 包管理器創(chuàng)建 React 應(yīng)用程序 npx create-react-app appName


或者應(yīng)該將反應(yīng)腳本鏈接到您的html


<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>


也不能重新定義文檔對(duì)象。這將引用您的網(wǎng)頁,您可以使用文檔對(duì)象訪問元素或 DOM(文檔對(duì)象模型)。


查看完整回答
反對(duì) 回復(fù) 2022-09-02
?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

根據(jù) https://reactjs.org/docs/add-react-to-a-website.html,您需要在導(dǎo)入腳本之前將以下兩行添加到HTML文件中:


<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script> 

<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>

我不確定模塊加載是否會(huì)按照你想要的方式工作,而不使用像Create React App這樣的東西。您可以刪除導(dǎo)入語句,并且仍然可以在腳本中引用 React 和 ReactDOM。


例如:


'use strict';


const e = React.createElement;


class LikeButton extends React.Component {

  constructor(props) {

    super(props);

    this.state = { liked: false };

  }


  render() {

    if (this.state.liked) {

      return 'You liked comment number ' + this.props.commentID;

    }


    return e(

      'button',

      { onClick: () => this.setState({ liked: true }) },

      'Like'

    );

  }

}


// Find all DOM containers, and render Like buttons into them.

document.querySelectorAll('.like_button_container')

  .forEach(domContainer => {

    // Read the comment ID from a data-* attribute.

    const commentID = parseInt(domContainer.dataset.commentid, 10);

    ReactDOM.render(

      e(LikeButton, { commentID: commentID }),

      domContainer

    );

  });


查看完整回答
反對(duì) 回復(fù) 2022-09-02
  • 3 回答
  • 0 關(guān)注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)