Last active
January 28, 2021 05:23
-
-
Save LeandrodeLimaC/321ce65c2bc6a50f0fc540754135bf7b to your computer and use it in GitHub Desktop.
Insert dynamic component in a vue instance (as Plugin)
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
import snackBarComponent from '@/components/global/snackBar'; | |
const snackBarPlugin = { | |
install: (Vue, options = {}) => { | |
let isHolderCreated = false; | |
const idName = 'snackbar', | |
ToastConstructor = Vue.extend(snackBarComponent); | |
const createHolder = () => { | |
let holder = document.createElement('div') | |
holder.id = idName; | |
document.getElementById("app").appendChild(holder); | |
isHolderCreated = true; | |
} | |
Vue.prototype.$notifier = { | |
showMessage: ({ message = '', color = 'primary' }) => { | |
if (!isHolderCreated) createHolder(); | |
let instance = new ToastConstructor({ | |
...options, | |
data: { | |
show: true, | |
message, | |
color | |
} | |
}) | |
instance.$mount(`#${idName}`); | |
} | |
} | |
} | |
} | |
export default snackBarPlugin; |
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 > | |
<v-snackbar class=" ml-10 mb-10" color="primary" v-model="isShowToast" :left="true"> | |
<p class="ma-0" style="padding-right: 20px">APLICAÇÃO ANTI PALIVIZUMABE SUPERIOR 3KG inserida na lista de baixas</p> | |
<template v-slot:action="{ attrs }"> | |
<v-btn | |
color="white" | |
text | |
v-bind="attrs" | |
@click="isShowToast = false" | |
> | |
Fechar | |
</v-btn> | |
</template> | |
</v-snackbar> | |
</template> | |
<script> | |
export default { | |
created(){ | |
console.log('aaa') | |
} | |
} | |
</script> | |
<style scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment