[Vuejs]-TypeError: "setting getter-only property vuejs axios

0👍

try to change

reader.onload = function oldyfunt(event) {

by

reader.onload = (event) => {

it should fix your problem

this refer to current scope, in your case this refer to oldyfunt function not vue instance

you can go deeper for arrow function here

0👍

You can’t use this reference inside an axios callback function, you can instead define this function in your methods and pass it to axios:

methods: {
  ...
  afterPostRequest(response) {
    console.log(response);
    this.result = response.data;
    console.log('SUCCESS!!');
  },
  handleFileChanges(e) {
    ...
    const afterPostRequest = this.afterPostRequest;
    reader.onload = function oldyfunt(event) {
      ...
      axios.post('http://0.0.0.0:9094/analyze',
        ...
      ).then(afterPostRequest).catch((error) => {
        console.log(error);
        console.log('FAILURE!!');
      });
    };
    ...
  },
  ...
},

Leave a comment