简单的将数据复制到剪贴板
npm i @kunping/clipboard --save
import clipboard from "@kunping/clipboard"
clipboard({data: "copy data"}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
// copy data
const data = ['hello',"world"]
clipboard({data}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
/*
hello
world
*/
const data = {
age: 12,
name: 'userName'
}
clipboard({data}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
/*
age:12
name:userName
*/
默认为:
const data = {
age: 12,
name: 'userName'
}
clipboard({data, separator: '-'}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
/*
age-12
name-userName
*/
默认为\n
const data = {
age: 12,
name: 'userName'
}
clipboard({data, rowSeparator: ','}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
/*
age:12,name:userName,
*/
当有弹框时,不支持navigator.clipboard
的浏览器无法复制到剪切板。这时需将当前弹框的Element
传入
clipboard({data: "copy data", container: html}).then(()=> {
alert('ok')
}).catch(() => {
alert('fail')
})
// copy data