Skip to content
Advertisement

Vuejs problems with implement a global confirm dialog feature

I’m implementing a global confirm dialog feature.

For example: The confirm dialog will open when a user clicks a “publish” button to publish an article.

  1. The user clicks the publish button triggers the function “openConfirmDialog()”.
  2. Show the confirm dialog.
  3. Wait for the user to click the “confirm” button.
  4. The function( onConfirm() ) in “confirmDialog.vue” will be triggered when the confirm button is clicked.

Questions:
How can I pass and trigger a dynamic action(in this example: pubishArticle ) when the user click the “confirm” button?


Component – confirmDialog.vue Cancel button:

JavaScript

Confirm button:

JavaScript

confirm dialog vuex module store actions:

JavaScript

Confirm button action:

JavaScript

frontend views – demo.vue:

JavaScript

publish article vuex module store action:

JavaScript

Advertisement

Answer

You could try sending the buttons definition inside openConfirmDialog:

JavaScript

OR

You could just emit a custom event on button click and let the parent component handle it.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement