React 在 html 中 CDN 引入(包含 useState、antd、axios ....)

一、简介

  • cdn 获取推荐 https://unpkg.comunpkg 是一个快速的全球内容交付网络,适用于 npm 上所有内容。

  • 【必备】react 相关 cdn。附:github 官方文档获取现阶段官方文档 CDN 网址

    ```html

    ```

  • 【必备】babel 相关 cdn

    ```html

    ```

  • 【可选】其他辅助库相关 cdn

    ```html

    rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.2/antd.compact.min.css"> ```

二、案例

image.png

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> <!-- react 相关 --> <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script> <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> <!-- axios --> <script type="text/javascript" src="https://unpkg.com/axios/dist/axios.min.js"></script> <!-- antd --> <script src="https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.2/antd.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/antd/4.18.2/antd.compact.min.css"> <!-- 样式 --> <style> .title { color: red; } </style> </head> <body> <!-- React 容器 --> <div id="app"></div> <!-- 告诉 babel 转哪些,只需要在 script 标签写 type="text/babel" 就可以了 --> <script type="text/babel"> // 组件内容 const Text = (props) => { // useState 使用 const [name, setName] = React.useState('张三') // 渲染 return ( <div className="title">组件内容</div> ) } // 页面内容 const Page = (props) => { const touchClick = () => { console.log('点击 + 1') } return ( <div> <Text /> <antd.Button type="primary" onClick={touchClick}>Primary Button</antd.Button> </div> ) } // 将页面内容渲染到指定容器 ReactDOM.render(<Page />, document.querySelector("#app")) </script> </body> </html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卡尔特斯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值