noobcode0000
noobcode0000

Reputation: 243

How would I close my application on button click in electron?

I am making a frameless application using electron and vuejs and I would like to know how I would go abouts closing the app once the exit button is clicked.

I have tried using this code in home.vue but it was not successful, as it just made my app blank:

<script>
  const remote = require('electron').remote
  export default {
     data(){
       return{
          w: remote.getCurrentWindow(),
       }
     },
  methods: {
    close(){
      this.w.close()
    },
  }
} 
</script>

Since I am still new to this and have only started out, what other methods can I use and what have I done wrong? Any help would be appreciated.

Upvotes: 0

Views: 874

Answers (2)

noobcode0000
noobcode0000

Reputation: 243

If anyone else comes across this, the following code worked for me (in Home.vue):

<v-btn @click='buttonClose'></v-btn>

...

<script>
methods: {

            buttonClose: function () {
                window.close();
            }
}
</script>

Thanks to garudamon and dj burb for leading me to the solution

Upvotes: 0

garudamon
garudamon

Reputation: 197

refer to this document, you can use app.exit()

const { app } = require('electron')
export default {
  methods: {
    buttonClose: function() {
      app.quit();
    }
  }
};

Upvotes: 1

Related Questions