//html
<div class="detailInfo" ref="detailInfo" v-html="invoicetInfoHTML"></div>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogNewVisible = false">关 闭</el-button>
<el-button type="primary" @click="submitCopy()">复制信息</el-button>
</div>
const info = {
type: "xxx",
title: "xxx",
address: "xxx",
iphone: "xxx",
};
const infoItem = [
{
title: "xxx:",
value: info.type
},
{
title: "xxx:",
value: info.title
},
{
title: "xxx:",
value: info.address
},
{
title: "xxx:",
value: info.iphone
}
];
this.infoItem = infoItem;
this.infoItem.map(item => {
this.invoicetInfoHTML += item.title + item.value + "<br />";
this.invoicetInfoJS += item.title + item.value + "\n";
});
submitCopy() {
this.Copy();
},
Copy() {
return new Promise(resolve => {
const copyUrl = document.createElement("textarea");
copyUrl.value = this.invoicetInfoJS;
const appDiv = document.getElementById("app");
appDiv.appendChild(copyUrl);
copyUrl.select();
document.execCommand("Copy");
copyUrl.remove();
resolve(true);
this.$message({
message: "复制成功",
type: "success"
});
});
}