[Vuejs]-Why does my webpage refresh when I execute the "save" function in Django?

0πŸ‘

βœ…

I use Visual Studio to open the port, and I found that separating the upload path and the web page path prevents the webpage from refreshing. Although I’m not sure why this happens, I have successfully resolved this issue.

0πŸ‘

The webpage refreshes after executing the "save()" function in Django because the form submission is triggering a default behavior of refreshing the page. To prevent this, you can modify your Vue code by removing the "onsubmit" attribute from the form tag and handling the form submission using the Vue method.

Here’s the updated code:

<form>
  <input type="file" ref="fileInput" />
  <button type="button" @click="upload">Upload</button>
</form>

In your Vue method, remove the line event.preventDefault(); as it is not needed anymore.

async upload() {
  //event.preventDefault(); 
}

Leave a comment