就类似于 segmentfault 编辑器这样的功能。
实现思路是什么呢?
就是操作剪贴板,将图片读取出来然后上传就行了
https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem
async function getClipboardContents() {
try {
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
const blob = await clipboardItem.getType(type);
// we can now use blob here
}
}
} catch (err) {
console.error(err.name, err.message);
}
}
然后可能会涉及到光标的操作,可以参考这篇文章:https://segmentfault.com/a/1190000041457245