[Vuejs]-XML file to String using JS/VueJS (sending it to backend server)

0đź‘Ť

âś…

You don’t need pass xml to send function because your xml string is property of Vue instance. Change send function to this:

send(){
    const url = this.$session.get('apiUrl') + 'manualReceive'
    this.submit('post',url, this.xml);
}

And in template:

<span class="logInBTN" v-on:click="send">Send</span>

UPDATE

Also you don’t need to assign this.xml in this line:

this.xml = reader.readAsText(file);

Just use:

reader.readAsText(file);

UPDATE 2

You use function word in function declaration in “load” event so this variable is FileReader.
You should store correct this or use arrow functions:

var self = this;
reader.addEventListener('load', function(){
      self.xml = reader.result;
      console.log("Result:\n\n" + self.xml);
    });

Then this.xml will work in send function.

Leave a comment