<template>
<view>
<view style="width:100rpx;height:100rpx;border:1px solid #222;margin: 10rpx;" v-for="(item,index) in imgList">
<image :src="item" mode="aspectFill" class="imgs"></image>
</view>
<button @click="submit">提交</button>
</view>
</template>
<script>
export default {
data() {
return {
imgList:[]
}
},
methods: {
submit(){
},
},
mounted() {
var _this=this;
// 监听 ctrl+v键盘事件
document.addEventListener('paste', function (event) {
var items = event.clipboardData && event.clipboardData.items;
var file = null;
if (items && items.length) {
// 检索剪切板items
for (var i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image') !== -1) {
file = items[i].getAsFile();
break;
}
}
}
var reader = new FileReader()
reader.onload = function(event) {
// event.target.result就是图片的Base64地址啦
console.log(event.target.result);
_this.imgList.push(event.target.result);
}
reader.readAsDataURL(file);
// console.log(file)
});
}
}
</script>
<style>
</style>