简体   繁体   English

如何从 vue 中的 main.js 文件重新渲染组件?

[英]How to re render component from main.js file in vue?

I want to rerender my component notfication.vue from main.js.我想从 main.js 重新渲染我的组件notfication.vue

main.js file is available globally. main.js 文件在全球范围内可用。

In this file, I am receiving notification.在这个文件中,我收到了通知。 After receiving the notification, I want to rerender component.收到通知后,我想重新渲染组件。

PushNotifications.addListener('pushNotificationReceived', 
  async (notification) => {
    // Rerender notification component from here

    notificationComponent ???

  }
);

One solution would be to use state management for example vuex, put notificationComponentKey as a state and put it on your component <notification-component:key="notificationComponentKey" and everytime you get a notification you do notificationComponentKey++;一种解决方案是使用 state 管理,例如 vuex,将notificationComponentKey作为 state 并将其放在您的组件<notification-component:key="notificationComponentKey"上,并且每次收到通知时都会执行notificationComponentKey++; which rerenders the component.重新渲染组件。

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

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