是否可以在CDN的浏览器中使用react-select? [英] Is it possible to use react-select in the browser from the cdn?

查看:64
本文介绍了是否可以在CDN的浏览器中使用react-select?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以直接在浏览器中使用react-select而无需如今的捆绑包?

Is it possible to use react-select directly from the browser without bundlers nowadays?

我发现可以执行此操作的最新版本是2.1.2:如何从React导入-使用React选择CDN和通天塔?

The most recent version that I found to be able to do so was 2.1.2: How to import from React-Select CDN with React and Babel?

那时,他们曾经以umd格式提供 react-select.min.js .

They used to provide react-select.min.js in the umd format back then.

如今,他们有 react-select.browser.esm.js react-select.browser.cjs.js (

Nowadays they have react-select.browser.esm.js and react-select.browser.cjs.js (https://unpkg.com/browse/react-select@3.1.0/dist/), but I couldn't get any of those working from the browser.

推荐答案

我知道了.希望这可以帮助其他人.永不放弃.

I figured out. Hope this can help others. Never give up.

react-select v3(目前为v3.1.1)不再具有独立的lib,因此使用它的唯一方法是使用v2.

react-select v3 (v3.1.1 at this moment) doesn't have standalone lib anymore, so the only way to use it is by v2.

要使用v2,您需要首先包含所有依赖项.

To use v2, you will need to include all the dependences first.

<div id="root"></div>

<script src="https://unpkg.com/react@17/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone@7.12.7/babel.min.js"></script>
<script src="https://unpkg.com/prop-types@15.7.2/prop-types.js"></script>
<script src="https://unpkg.com/classnames@2.2.6/index.js"></script>
<script src="https://unpkg.com/react-input-autosize@2.2.2/dist/react-input-autosize.js"></script>
<script src="https://unpkg.com/emotion@10.0.27/dist/emotion.umd.min.js"></script><script src="https://unpkg.com/react-select@2.4.4/dist/react-select.js"></script>

<script type="text/babel">

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' },
];

    class Hello extends React.Component {
        render() {
            return <Select options={options} />;
        }
    }
    ReactDOM.render(
        <Hello />,
        document.getElementById('root')
    );
</script>

这篇关于是否可以在CDN的浏览器中使用react-select?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆