--- title: 代码复制 author: pengzhanbo createTime: 2024/03/06 16:24:34 permalink: /config/plugins/copy-code/ --- ## 概述 主题内置的代码复制插件,在代码块中插入复制按钮。 关联插件: [@vuepress-plume/plugin-copy-code](https://github.com/pengzhanbo/vuepress-theme-plume/tree/main/plugins/plugin-copy-code) 默认配置: ```ts{7-9} import { plumeTheme } from 'vuepress-theme-plume' import { defineUserConfig } from 'vuepress' export default defineUserConfig({ theme: plumeTheme({ plugins: { copyCode: { selector: '.page-content div[class*="language-"] pre', }, } }), }) ``` ## 配置 ### selector - 类型: `string` - 默认值: `'.page-content div[class*="language-"] pre'` 用于指定复制按钮应用的代码块选择器。 ### duration - 类型: `number` - 默认值: `1500` 用于置顶 提示消息显示时间。 设置为 `0` 将会禁用提示。 ### showInMobile - 类型: `boolean` - 默认值: `false` 用于控制是否在移动端显示复制按钮。 ## 禁用 你可以指定 `copyCode: false` 来禁用插件。 ```ts{7} import { plumeTheme } from 'vuepress-theme-plume' import { defineUserConfig } from 'vuepress' export default defineUserConfig({ theme: plumeTheme({ plugins: { copyCode: false, } }), }) ```