Last active
January 7, 2021 19:58
-
-
Save gastonambrogi/4f88a5fea4bfb2d5191fc7102f8237ef to your computer and use it in GitHub Desktop.
attach canvas data to form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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