【问题标题】:How to re render component from main.js file in vue?如何从 vue 中的 main.js 文件重新渲染组件?
【发布时间】:2021-07-16 16:41:06
【问题描述】:

我想从 main.js 重新渲染我的组件 notfication.vue

main.js 文件在全球范围内可用。

在这个文件中,我收到了通知。收到通知后,我想重新渲染组件。

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

    notificationComponent ???

  }
);

【问题讨论】:

    标签: javascript vue.js vuex vuejs3


    【解决方案1】:

    一种解决方案是使用状态管理,例如 vuex,将 notificationComponentKey 作为状态并将其放在您的组件 <notification-component :key="notificationComponentKey" 上,每次收到通知时您都会执行 notificationComponentKey++; 重新渲染组件。

    【讨论】:

      猜你喜欢
      • 2017-11-09
      • 1970-01-01
      • 2019-07-03
      • 2017-05-08
      • 1970-01-01
      • 2018-10-19
      • 2018-05-04
      • 2020-02-13
      • 1970-01-01
      相关资源
      最近更新 更多