Last active
January 26, 2019 07:00
-
-
Save reg2005/3bc5ee4e6e50c282f4c4aff9879e7e9c to your computer and use it in GitHub Desktop.
Simple code for use Replain chat in your SPA VueJS projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div></div> | |
</template> | |
<script> | |
const elementId = 'replain-script' | |
export default { | |
props: { | |
code: { | |
default: null | |
} | |
}, | |
mounted() { | |
if(!this.code){ | |
console.log('REPLAIN_CODE_IS_NOT_SET') | |
return | |
} | |
window.__REPLAIN_ = this.code; | |
let element = document. getElementById(elementId); | |
if(element){ | |
element.parentNode.removeChild(element); | |
} | |
let reScript = document.createElement('script') | |
reScript.setAttribute('src', 'https://widget.replain.cc/dist/client.js') | |
reScript.setAttribute('id', elementId) | |
document.head.appendChild(reScript) | |
}, | |
beforeDestroy() { | |
let elementId = '__replain_widget' | |
let element = document. getElementById(elementId); | |
if(element){ | |
element.parentNode.removeChild(element); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment