How to create reusable functions in Vuejs?

I have this function in a Vuejs File which calls another function which is imported from a JS File.

Demo.vue

import Data from "demofile.js"

created(){
  this.getResult()
}

methods(){
async getResult(){
      Data.example() // Fetching Data from API
      .then((results) =>{
        this.$set(this,"results",results) // storing in event data()
        console.log(this.results)
    })
    .catch(e =>console.log(e, "Error from catch"))
  }
 }

I want to make this function reusable so that I could use it on any other VueJS files.



Read more here: https://stackoverflow.com/questions/65718347/how-to-create-reusable-functions-in-vuejs

Content Attribution

This content was originally published by pranshu verma at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: