简体   繁体   English

在 Nuxt.js 中重定向页面后如何显示通知消息?

[英]How can I show notification message after redirect a page in Nuxt.js?

I've searched for this problem a lot.我已经搜索了很多这个问题。 But I couldn't find any solve.但我找不到任何解决办法。 Please help me.请帮我。

I want to redirect a page in middleware.我想在中间件中重定向页面。 And then showing notification (with vue-notification).然后显示通知(使用 vue-notification)。 I can to that when page loaded.我可以在页面加载时做到这一点。 But if the user tries to get that page in URL, I want to redirect again.但是如果用户试图在 URL 中获取该页面,我想再次重定向。 But still showing notification message.但仍然显示通知消息。 :) :)

Thank you everyone.谢谢大家。

I also had the same problem and here is my workaround.我也遇到了同样的问题,这是我的解决方法。

On the middleware file, return redirect to the desired page then add an optional query parameter that you would check against on the desired page when it loads.在中间件文件上,返回重定向到所需页面,然后添加一个可选的查询参数,您将在所需页面加载时检查该参数。 then on conditional check against that query parameter, you pop up a notification.然后根据该查询参数进行条件检查,您会弹出一个通知。 You can use noty plugin to display the notification.您可以使用noty 插件来显示通知。

So in summary...所以总结...

//In middleware file
return('/to/desired/page?queryName=queryValue')

//In Desired Page file
<script>
...
mounted(){
   if(this.$route.query.queryName == queryValue){
     
    this.$noty.error('your notification message here')
    // or .info  or .warning ...check the link for more
  }
}
...
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM