The parent component passes a value to the child component, and the child component receives it and renders it again.

problem description

wrote a sub-component for uploading images. The only ID field for the first upload is empty. After the upload is successful, the backend returns a unique id, for the second upload, the previous id will be written into the parameters and then uploaded.

the problem now is that id could not be written into the parameters the second time. Each upload will generate a new id;

.

related codes

  • template Code

parent component,


</upload-case-img-two>


....
// 
    bindFace(val){
      console.log(val);
      this.categoryId = val.categoryId
   }

subcomponents

<template>
  <vue-dropzone
    ref="twoVueDropzone"
    id="dropzone"
    :options="dropzoneOptions"
    @vdropzone-success="vsuccess"
  ></vue-dropzone>
</template>

// Dropzone
...
props:{
    categoryId: {
      type: String,
      default:""
    }
}
data: function() {
    return {
      // backUrl:"",
      
      Dropzone: null,
      dropzoneOptions: {
        url: "/common/oss/upload_by_category_id",
        paramName: "file",
        params:  {imageName: this.desc, categoryId: this.categoryId, orderSort:this.order} ,
        thumbnailWidth: 150,
        maxFilesize: 1, // 
        maxFiles: 1, // 
        addRemoveLinks: true,
        headers: { "My-Awesome-Header": "header value" },
        dictDefaultMessage: `<i class="fa fa-cloud-upload"></i></br>${
          this.desc
        }`,
        dictRemoveLinks: "",
        dictCancelUpload: "", // 
        dictInvalidInputType: "", // 
        dictCancelUploadConfirmation: "", //
        dictFileTooBig: "", // 
        dictRemoveFile: "", // 
        dictMaxFilesExceeded: "" //
      }
    };
  },
// categoryId
watch: {
    categoryId(newValue, oldValue) {
        console.log(`${oldValue}`);
        this.categoryId = newValue;
        console.log(`id${this.categoryId}`);
      }
  },

demand

I don"t know how to reinitialize the upload component when the categoryId of the subcomponent changes (when there is a value) so that the parameters are passed in. Ask for advice

Jan.08,2022

use a hack method:

< component >
Vmurf = "hackReset"
< / component >

this.hackReset = false;

  this.$nextTick(() => {
    this.hackReset = true;
  });
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf81d8-320bb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf81d8-320bb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?