From 55d8999eb32599ca86b6cffc9b2368a5e973f625 Mon Sep 17 00:00:00 2001 From: Dan Luchs Date: Mon, 20 Nov 2023 15:04:47 -0700 Subject: [PATCH] Changing the Vue prototype object to work with Vue 2 or 3. --- src/sanitize.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sanitize.ts b/src/sanitize.ts index eaac795..5d0db3b 100644 --- a/src/sanitize.ts +++ b/src/sanitize.ts @@ -52,7 +52,10 @@ const VSanitize = { const { name = 'sanitize' } = defaultOptions; delete defaultOptions.name const options1 = { ...defaultOptions } as IOptions - Vue.prototype[`$${name}`] = (dirty: string, opts = undefined) => sanitizeHtml(dirty, opts || options1); + + const vueProto = Vue?.config?.globalProperties ?? Vue.prototype; + vueProto[`$${name}`] = (dirty: string, opts = undefined) => sanitizeHtml(dirty, opts || options1); + Vue.directive(name, (el, binding) => { if (binding.value !== binding.oldValue) { if (Array.isArray(binding.value)) {