# Copy Code 快捷复制代码
通过按钮快速复制代码块
# Import:
import VueMarkdownEditor from '@kangc/v-md-editor';
import createCopyCodePlugin from '@kangc/v-md-editor/lib/plugins/copy-code/index';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
VueMarkdownEditor.use(createCopyCodePlugin());
# Usage:
<template>
<v-md-editor v-model="text" height="500px" @copy-code-success="handleCopyCodeSuccess" />
</template>
<script>
export default {
data() {
return {
text: `\`\`\`js
import Vue from 'vue';
import VueMarkdownEditor from '@kangc/v-md-editor';
import '@kangc/v-md-editor/lib/style/base-editor.css';
import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
VueMarkdownEditor.use(vuepressTheme);
Vue.use(VueMarkdownEditor);
\`\`\`
`,
};
},
methods: {
handleCopyCodeSuccess(code) {
console.log(code);
},
},
};
</script>
# 使 preview html 组件支持复制代码功能:
import VMdPreviewHtml from '@kangc/v-md-editor/lib/preview-html';
import createCopyCodePreview from '@kangc/v-md-editor/lib/plugins/copy-code/preview';
import '@kangc/v-md-editor/lib/plugins/copy-code/copy-code.css';
VMdPreviewHtml.use(createCopyCodePreview());