<input type="file"
id="fieldBoxContentAddPhoto"
accept="image/png"
@input="inputPhoto(this,fieldBoxContentAddPhoto2,fieldBoxContentAddPhoto3)"
>
<img alt=""
ref="fieldBoxContentAddPhoto2"
src="fieldBoxContentAddPhoto3"
style="width:150px;height:150px"
>
const fieldBoxContentAddPhoto2 = ref();
const fieldBoxContentAddPhoto3 = ref();
function inputPhoto(p,p2,p3){
console.log(p); //output is not the input element?
console.log(p2); //output the img element
console.log(p3); //output undefined?
}
1: In HTML oninput event passing 'this' will output the input element, how to do the same in @input?
2: How to output fieldBoxContentAddPhoto3 correctly, so that I can set 'p3.value = xxx;'? I know I can use 'p2.src = xxx;', but in some situations, I need to pass the ref to the function directly. Suppose I having many input+img elements in a page and need to call the same inputPhoto function for doing the same logic.
p,p2andp3honestly.thisis the event object that you're receiving from Vue and that you could use to access the element in the same way as in HTML with$event.target.fieldBoxContentAddPhoto2is indeed having the ref element as expected. You should not usefieldBoxContentAddPhoto3in theinputPhotofunction withp3.value = xxxbut ratherfieldBoxContentAddPhoto3.valuedirectly and then use:src="fieldBoxContentAddPhoto3"on theimgelement. Call theinputPhotoand update the refs rather than trying to hack the DOM, this is not how Vue is supposed to work.fieldBoxContentAddPhoto3a dynamic value that could be generic and used in several places.