Skip to content

Instantly share code, notes, and snippets.

@reg2005
Last active Jan 26, 2019
Embed
What would you like to do?
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