Skip to content

Instantly share code, notes, and snippets.

@gastonambrogi
Last active January 7, 2021 19:58
Show Gist options
  • Save gastonambrogi/4f88a5fea4bfb2d5191fc7102f8237ef to your computer and use it in GitHub Desktop.
Save gastonambrogi/4f88a5fea4bfb2d5191fc7102f8237ef to your computer and use it in GitHub Desktop.
attach canvas data to form
const canvas = document.getElementById('my-canvas');
canvas.toBlob(function(blob) {
const formData = new FormData();
formData.append('my-file', blob, 'filename.png');
// Post via axios or other transport method
axios.post('/api/upload', formData);
});
import myImage from "./assets/bg.png";
export default {
name: 'levelOne',
data: () => ({
}),
methods:{
func(){
let cvn = this.$refs.canvas;
let ctx = cvn.getContext("2d");
let bg = new Image();
bg.src = myImage;
bg.onload = function() {
ctx.drawImage(bg, 0 ,0);
};
}
},
mounted(){
this.func();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment