Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added a button to copy, axios/axios #6663 #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions posts/en/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,48 @@ Using npm:
```bash
$ npm install axios
```
<button onclick="copyToClipboard('npm install axios')">Copy</button>

Using bower:

```bash
$ bower install axios
```

<button onclick="copyToClipboard('bower install axios')">Copy</button>
Using yarn:

```bash
$ yarn add axios
```

<button onclick="copyToClipboard('yarn add axios')">Copy</button>
Using jsDelivr CDN:

```html
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
```
<button onclick="copyToClipboard('<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>')">Copy</button>

Using unpkg CDN:

```html
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
```

<button onclick="copyToClipboard('<script src="https://unpkg.com/axios/dist/axios.min.js"></script>')">Copy</button>
Prebuilt CommonJS modules for direct importing with require (if your module bundler failed to resolve them automatically)

```js
const axios = require('axios/dist/browser/axios.cjs'); // browser
const axios = require('axios/dist/node/axios.cjs'); // node
```
<button onclick="copyToClipboard('const axios = require('axios/dist/browser/axios.cjs');
const axios = require(\'axios/dist/node/axios.cjs\'); // node')">Copy</button>

<script>
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
alert('Copied to clipboard!');
}).catch(err => {
console.error('Failed to copy: ', err);
});
}
</script>