vue-image-diff-example3
by whwnsdlr1
HTML
<script src="https://unpkg.com/vue@2.6.14"></script>
<script src="https://unpkg.com/vue-image-diff"></script>
<div class="row1">
<input type="file" accept=".png,.jpg" multiple />
</div>
<div class="row2 container">
<vue-image-diff :data="data" :options="options" />
</div>
CSS
html,
body {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.row1 {
display: flex;
flex: 0 0 30px;
min-height: 0;
justify-content: center;
align-items: center;
}
.row2.container {
width: 100%;
flex: 1 0 0;
}
JavaScript
function convertFileToDatum (files) {
let data1 = []
for (const [cnt, file] of Object.entries(files)) {
data1.push(
{id: `id-${cnt}`,
blob: file,
name: file.name,
ext: file.name.match('.[a-zA-Z]+$')[0]})
}
return data1
}
data = []
options = {style: {borderColor:[255, 0, 255]}}
// options = {}
let component = new Vue ({
el: '.container',
data: function () {
return {
data,
options
}
},
components: {
'vue-image-diff': vueImageDiff
}
})
console.log(component.$refs)
document.querySelector('.row1 input').onchange = function (e) {
r = parseInt(Math.random() * 255)
g = parseInt(Math.random() * 255)
b = parseInt(Math.random() * 255)
console.log([r,g,b])
/*
component.setState({
style: {
borderColor: [r,g,b]
}
})
*/
component.data = convertFileToDatum(e.target.files)
}