🐛[完善]lay-code 文档 demo 代码复制功能
This commit is contained in:
parent
09f1472058
commit
6d0600fcc1
@ -19,6 +19,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { layer } from '@layui/layer-vue'
|
||||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
const meta = ref<HTMLElement>({} as HTMLElement)
|
const meta = ref<HTMLElement>({} as HTMLElement)
|
||||||
@ -32,9 +33,14 @@ const toggle = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const copy = function () {
|
const copy = function () {
|
||||||
var Url2 = document.getElementById('source') as any
|
const foundCodes = meta.value.getElementsByClassName('language-html')
|
||||||
Url2.select()
|
if (document.hasFocus()) {
|
||||||
document.execCommand('Copy')
|
const text = foundCodes[0].textContent || "";
|
||||||
|
navigator.clipboard.writeText(text);
|
||||||
|
layer.msg("复制成功", { icon : 1, time: 1000}, ()=>{})
|
||||||
|
} else {
|
||||||
|
layer.msg("复制失败", { icon : 2, time: 1000}, ()=>{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user