Skip to content

Commit c70c6fe

Browse files
committed
update: README.md
1 parent aa3e88f commit c70c6fe

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Import the npm package and only one prop to show highlightCode
1515
<img alt="Quality" src="https://npm.packagequality.com/shield/vue-highlight-code.svg">
1616
</a>
1717
</p>
18+
1819
```
1920
yarn add highlight.js vue-highlight-code
2021
```
22+
2123
## live demo
2224

2325
[stackblitz](https://stackblitz.com/edit/github-flf8ku?file=README.md)

src/components/CopyCode.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const props = defineProps({
1010
type: String,
1111
default: 'console.log(',
1212
required: true,
13-
}
13+
},
1414
})
1515
const copy = (event) => {
1616
getContent()
@@ -20,22 +20,25 @@ const copy = (event) => {
2020
const textarea = ref(null)
2121
const getContent = () => {
2222
let textArea = textarea.value
23-
console.log(textArea,'textArea')
23+
console.log(textArea, 'textArea')
2424
if (document.execCommand('copy') == true) {
25+
console.log('document.execCommandtrue')
2526
// older browser support
2627
let range, selection
2728
textArea.focus()
2829
textArea.select()
2930
range = document.createRange()
3031
range.selectNodeContents(textArea)
32+
console.log(range, 'range')
3133
selection = window.getSelection()
3234
selection.removeAllRanges()
3335
selection.addRange(range)
3436
textArea.setSelectionRange(0, textArea.value.length)
3537
document.execCommand('copy')
3638
} else {
3739
// modern browser support (using the clipboard API)
38-
navigator.clipboard.writeText(textArea.value)
40+
console.log('navigator.clipboard.writeText(textArea.value)')
41+
navigator.clipboard.writeText(props.codeValue)
3942
}
4043
}
4144
</script>
@@ -44,7 +47,12 @@ const getContent = () => {
4447
<!-- <input type="text" /> -->
4548
<div class="cb" tabindex="0" @focusout="resetMessage" @click="copy">
4649
<!-- <div class="cb_tooltip">{{ Tips }}</div> -->
47-
<textarea ref="textarea" :value="props.codeValue" tabindex="1" readonly></textarea>
50+
<textarea
51+
ref="textarea"
52+
:value="props.codeValue"
53+
tabindex="1"
54+
readonly
55+
></textarea>
4856
<div class="cb_copy">{{ text }}</div>
4957
<!-- <div v-show='copyjudge' class="cb_copy">copied</div> -->
5058
</div>

0 commit comments

Comments
 (0)