The method that the vue parent component invokes the child component and the return data is not available?

//index.vue 
img1:<uploadArea ref="upload1" :url="url"/>
img2:<uploadArea ref="upload2" :url="url"/>
<button @click="submit"></button>

//http
async submit () {
      let imgs1 = await this.$refs.upload1.uploadPic();
      let imgs2 = await this.$refs.upload2.uploadPic();
      console.log(imgs1[0])
}

//uploadImg.vue 
uploadPic() {
  //...
  return imgs  //ajaxhttp
}
The

process is to first click the submit button to trigger the submit method to execute the sub-component"s uploadPic method, upload the local image to the http link, and then execute the code under submit to submit the form. Because uploadImg.vue is a generic component, it cannot deal with business logic.

all images in the project are uploaded using the uploadImg.vue component, but some pages have multiple places to use the image upload component.
I have tried that I cannot upload imgs to the index page through return. Is there any other way to solve this problem?

Jul.01,2021

add this.$emit at the end of the uploadPic method in the child component ("actionName", imgs); so that you can throw the imgs to the parent component, and add @ actionName=handleAction (imgs) to the uploadArea tag of the parent component to accept the imgs passed by the child component


< hr >

uploadPic is not an asynchronous function and cannot be await. In addition, img appears only when it is read.

Menu