npm install --save vue-clipboard3
安装vue-clipboard3插件;
import useClipboard from 'vue-clipboard3'
const { toClipboard } = useClipboard()
在需要复制的页面引入;
// 复制快递单号,只能字符串,不然报错 const copy = async (msg) => { try { await toClipboard(msg) console.log('Copied to clipboard') } catch (e) { console.error(e) } }
最后通过调用copy方法即可,tips:传入参数需要字符串;传入数字的时候插件会报错