Skip to content

Instantly share code, notes, and snippets.

@reg2005
Last active January 26, 2019 07:00
Show Gist options
  • Save reg2005/3bc5ee4e6e50c282f4c4aff9879e7e9c to your computer and use it in GitHub Desktop.
Save reg2005/3bc5ee4e6e50c282f4c4aff9879e7e9c to your computer and use it in GitHub Desktop.
Simple code for use Replain chat in your SPA VueJS projects
<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