[Vuejs]-How do you handle it if you don't upload photos on vue Js?

0👍

instead of using this.$ref . try to make the formData property in data function and loop through key value object

//this is my example straight from my project
  data() {
    return {
      formData: {
        id: null,
        patient_id: this.patient.id,
        admission_date: "",
        discharge_date: "",
        provider: "",
        hospital: "",
        reason: "",
        attachment: null,
      },
    };
  },
    methods: {
    submitFormData() {
      let form = new FormData();

// here when data is submitted formData key value is being looped through new FormData
      for (var key in this.formData) {
        form.append(key, this.formData[key]);
      }
      axios
        .post("api.example.com/store", form, {
          header: {
            "Content-Type":
              "multipart/form-data"
          },
        })
        .then((res) => {
        console.log(res)
        })
        .catch(err => console.log(err.message));
    },

file attachment is attachment:null in this case initially

Leave a comment