Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert string with v-html #248

Closed
ianclever opened this issue Jul 14, 2021 · 3 comments
Closed

Insert string with v-html #248

ianclever opened this issue Jul 14, 2021 · 3 comments
Labels
Type: Enhancement New feature or request

Comments

@ianclever
Copy link

Please allow inserting plain html into the content, use v-html instead of plain text, to inject the content.

@ianclever ianclever added the Type: Enhancement New feature or request label Jul 14, 2021
@cliftonlabrum
Copy link

What you describe would be convenient. You may already be aware, but a workaround to get HTML into the toast is to use a component. Below is an example.

//Wherever your toast is triggered
import { useToast } from 'vue-toastification'
import Toasty from '@/components/widgets/Toasty.vue'
const toast = useToast()

function showMyToast(){
  let content = {
    component: Toasty,
    props: {
      title: text.title,
      message: text.message,
      type: 'success'
    }
  }

  toast(content)
}

Then you can do custom HTML in your Toasty.vue component:

<script>
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Toasty',
  props:{
    title: String,
    message: String,
    type: String
  }
})
</script>
<template>
  <!-- Anything you want in here populated with your props -->
  <div class="toast">
    <div class="icon" :class="type"></div>
    <div class="inside">
      <h5>{{ title }}</h5>
      <p>{{ message }}</p>
    </div>
  </div>
</template>

I hope that helps.

@ianclever
Copy link
Author

I've seen this, but in my case I have support for both toastr using vue and the version without vue, because on the system I work on, part is legacy, part is not.
In the case of the above example can I do this in the non vue version?

@ianclever
Copy link
Author

Hi, I did the tests following your suggestion and it worked. Thank you for your help!
I just didn't need to use "defineComponent".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants