标题使用Clipboard插件
下载插件
npm install clipboard
然后引入
// 全局中引入 main.js
import clipboard from 'clipboard'
Vue.prototype.clipboard = clipboard
// 局部引入
import clipboard from 'clipborad'
页面中
<div>
<div style="margin:0 0 1rem" v-html="downloadLink">{{ downloadLink }}</div>
<van-button
type="info"
size="mini"
:data-clipboard-text="downloadLink"
@click="copyFn"
id="copy_title"
>一键复制</van-button>
</div>
<script>
import Clipboard from "clipboard";
methods: {
copyFn() {
var clipboard = new Clipboard("#copy_title"); //拿到按钮的id
clipboard.on("success", e => { //复制成功
Toast("复制成功");
clipboard.destroy();
});
clipboard.on("error", e => { //失败
Message({
message: "该浏览器不支持复制",
type: "warning"
});
clipboard.destroy(); //清除缓存
});
},
}
</script>