[Vuejs]-How can I show different divs dynamically based on an ID received from an API response

0👍

You can make use of dynamic component feature of vue js, define your notification templates and then based on identifier set them dynamically, by using this method you can use single model for as many templates you want

Template structure will be like this

  • Components
    • Notifications
      • Template A
      • Tempalte B
      • Template C
      • —- etc.

In vue just model component make use of

<component :is="myDynamicComponent" :data="myDyanmicDataForComponent" />

Whenever you receive notification just set the template and data then make it visible.

Here is a working example:

https://codesandbox.io/s/vue-dynamic-template-example-gwt9d

Leave a comment