I need to pass the id parameter to my component and call its update (re-rending -> without reloading the page)
i have a component with avatars loading method
settings.vue
<template>
... download form and button with onUploadImg method
</template>
<script>
methods: {
onUploadImg() {
if(this.avatarFile == null) return;
var formData = new FormData();
formData.append("file", this.avatarFile);
axios.post('urlForPost',
formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
//response Ok, show message and reload img on this page
this.$nextTick(() => {
//Need send new FileId from image to MyVueAvatar.vue and update him
localStorage.setItem('picture', response.data); //can be through local storage?
})
})
.catch(error => {
console.log(error);
});
}
}
</script>
OrderContainer.vue
<template>
<my-vue-avatar class="img-avatar" :id="this.avatarPicId"></my-vue-avatar>
....
</template>
<script>
import MyVueAvatar from '../Avatar'
....
</script>
MyVueAvatar.vue (need to update this component if a new avatar has been uploaded to settings.vue)
<template>
<div>
<img :src="`data:image/png;base64, ${file}`" class="img-avatar" style="height: 35px;" />
</div>
</template>
<script>
import axios from 'axios'
export default {
props: {
id: null
},
data: () => {
return {
file: null
}
},
created() {
this.onGetImage(this.id);
},
methods: {
onGetImage(id) {
if (id == null) return;
axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.getItem('jwt');
axios.get('url/File/Get/' + id,
{
responseType: 'arraybuffer'
})
.then(r =>
{
var buffer = new Buffer(r.data, 'binary').toString('base64');
this.file = buffer;
})
.catch(error => {
console.log(error);
});
}
}
}
</script>
how can do this?
onGetImage(id)each time propidis changed?idchanged