shakee93 / vue-toasted

🖖 Responsive Touch Compatible Toast plugin for VueJS 2+
https://shakee93.github.io/vue-toasted/
MIT License
2.21k stars 195 forks source link

Pass a component as a parameter, instead of a String #160

Closed OssiPesonen closed 4 years ago

OssiPesonen commented 4 years ago

I've used react-toastify with React, which is a very similar package to this one, but the main difference between these two is that with React I an pass a component as a parameter. This allows me to use a reusable component with each toast, specifying in the attributes the title and message:

    toast.success(<NotificationContent title="I am a title" message="I am a message" />);

This would awesome as a feature. I did make it work by registering a custom toast that splits the message via a | delimiter:

Vue.toasted.register('htmlError',
    (payload) => {
      const split = payload.split('|');
      const title = split[0];
      const message = split[0];

        // if there is a message show it with the message
      return '<div class="notification-content with-title"><h3>' + title +'</h3>' + message + '</div>'
    },
  options
);

But this feels like a wobbly hack tbh. Would prefer to use a component I've created with props. Thoughts?

shakee93 commented 4 years ago

We cannot pass a vue component as vue-toasted doesn't use the template engine of vue. you can may try Vue.compiler to get around this.