Home  >  Q&A  >  body text

Success message displayed in Vue when data is saved successfully

<p><pre class="brush:php;toolbar:false;">axios .post( "/api/product/store",{ id: this.id }) .then((res) => { var variant = "danger"; var icon = "XIcon"; var message = "Thất bại"; if (res.data.error == 0) { var variant = "success"; var icon = "ArrowDownCircleIcon"; var message = res.data.message; window.location.reload(); } this.$toast({ component: ToastificationContent, props: { title: message, icon: icon, variant: variant, }, }); }) .catch((error) => { });</pre> <p>My problem is: it only loads the page when the message is displayed, so when the page reloads it loses the message. Is there a way to reload the previous page and then display the following message? Thanks. </p>
P粉878510551P粉878510551416 days ago457

reply all(1)I'll reply

  • P粉037215587

    P粉0372155872023-08-30 15:17:17

    What’s the point of reloading the page? If you want to display updated data on the user interface, Vue will do it for you automatically. So you don't need to do this.

    Alternatively, if page reloading is necessary for you, you can put the prompt message on the root page and call it from the current subpage. In this case, the message will be displayed regardless of whether you reload the page.

    reply
    0
  • Cancelreply