1. 程式人生 > 其它 >Vue中使用clipboard實現複製功能

Vue中使用clipboard實現複製功能

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="/new_website/scripts/layui/css/layui.css" rel="stylesheet" />
    <script src="../../new_website/scripts/jquery1.8.3/jquery-1.8.3.js"></script>
    <script src="/new_website/scripts/layui/layui.all.js"
></script> <script src="/new_website/scripts/vue/vue.js"></script> <script src="../../new_website/scripts/common/clipboard.min.js"></script> </head> <body> <p> <span>{{logisticsNumber}}</span> <span class="layui-btn-normal btnCopy"
:data-clipboard-text="logisticsNumber">複製單號</span> </p> <script type="text/javascript"> //複製操作 var clipboard = new ClipboardJS(".btnCopy"); clipboard.on('success', function (e) { layer.msg('複製成功'); e.clearSelection();
//console.log(e); }); clipboard.on('error', function (e) { layer.msg('複製失敗'); //console.log(e); }); </script> </body> </html>