A Vue directive which renders sanitised HTML dynamically
npm install vue-safe-html!Node




A Vue directive which renders sanitised HTML dynamically. Zero dependencies, compatible with Vue versions 3 and 2, TypeScript-ready.
Note: This library is not XSS-safe, but only strips tags programmatically.
Install package:
``sh`
npm install vue-safe-htmlOR
yarn add vue-safe-html
Use the plugin:
`js
import Vue from 'vue';
import VueSafeHTML from 'vue-safe-html';
Vue.use(VueSafeHTML);
`
In your component:
` Renders to: #### allowedTags Array of strings. Default: Customize the tags that are allowed to be rendered, either by providing new ones: Or extending the default ones: Vue.use(VueSafeHTML, { If no tags are passed, all tags are stripped: Vue.use(VueSafeHTML, { It is also possible to provide custom allowed tags directly to the directive tag, using directive modifiers. This allows local override of the option: #### allowedAttributes Array of strings. Default: [] Customize the tag attributes that are allowed to be rendered:html
``js`
export default {
computed: {
myUnsafeHTML() {
return ' I am safe!';
}
}
}`html`I am safe!['a', 'b', 'br', 'strong', 'i', 'em', 'mark', 'small', 'del', 'ins', 'sub', 'sup']$3
.`js`
Vue.use(VueSafeHTML, {
allowedTags: ['marquee', 'blockquote'],
});`js`
import VueSafeHTML, { allowedTags } from 'vue-safe-html';
allowedTags: [...allowedTags, 'marquee', 'blockquote'],
});`js`
import VueSafeHTML from 'vue-safe-html';
allowedTags: [],
});`html
``jsvue-safe-html` is written as a Vue plugin so you can easily use it inside Nuxt by following the Nuxt documentation.
Vue.use(VueSafeHTML, {
allowedTags: ['a'],
allowedAttributes: ['title', 'class', 'href'],
});$3
License