vue的全局提示框組件實(shí)例代碼
這篇文章給大家介紹一個(gè)vue全局提示框組件,具體代碼如下所示:
<template>
<!-- 全局提示框 -->
<div v-show="visible" class="dialog-tips dialog-center">
<div>{{message}}</div>
</div>
</template>
<script>
export default {
data() {
return {
visible: false,
message: ""
};
}
};
</script>
<style lang="scss">
.dialog-tips{
position: fixed;
z-index: 100;
min-width: 220px;
padding: 40px 22px;
white-space: nowrap;
background-color: #fff;
box-shadow: 0px 8px 15px 0 rgba(0, 0, 0, 0.1);
text-align: center;
.dialog-tips-icon{
width: 54px;
height: 54px;
@extend %bg-contain;
display: inline-block;
margin-bottom: 13px;
}
}
.dialog-center {
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
}
</style>
toast.js
import ToastComponent from './toast.vue'
const Toast = {};
// 注冊(cè)Toast
Toast.install = function (Vue) {
// 生成一個(gè)Vue的子類
// 同時(shí)這個(gè)子類也就是組件
const ToastConstructor = Vue.extend(ToastComponent)
// 生成一個(gè)該子類的實(shí)例
const instance = new ToastConstructor();
// 將這個(gè)實(shí)例掛載在我創(chuàng)建的div上
// 并將此div加入全局掛載點(diǎn)內(nèi)部
instance.$mount(document.createElement('div'))
document.body.appendChild(instance.$el)
// 通過Vue的原型注冊(cè)一個(gè)方法
// 讓所有實(shí)例共享這個(gè)方法
Vue.prototype.$toast = (msg, duration = 1500) => {
instance.message = msg;
instance.visible = true;
setTimeout(() => {
instance.visible = false;
}, duration);
}
}
export default Toast
如何使用?
在main.js中
import Vue from 'vue' import Toast from './toast' Vue.use(Toast);
在component中
this.$toast("XXXXXXXXX");
總結(jié)
以上所述是小編給大家介紹的vue的全局提示框組件實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Vue編譯器源碼分析compileToFunctions作用詳解
這篇文章主要為大家介紹了Vue編譯器源碼分析compileToFunctions作用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
vue使用element-resize-detector監(jiān)聽元素寬度變化方式
這篇文章主要介紹了vue使用element-resize-detector監(jiān)聽元素寬度變化方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
antd vue table跨行合并單元格,并且自定義內(nèi)容實(shí)例
這篇文章主要介紹了antd vue table跨行合并單元格,并且自定義內(nèi)容實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-10-10
vue3?實(shí)現(xiàn)右鍵菜單編輯復(fù)制粘貼功能
在瀏覽器中,Vue3編輯器自帶默認(rèn)右鍵菜單,然而,在Electron桌面應(yīng)用中,這一功能需自行編寫代碼實(shí)現(xiàn),本文詳細(xì)介紹了如何在Vue3中手動(dòng)實(shí)現(xiàn)右鍵菜單的編輯、復(fù)制、粘貼功能,并提供了代碼示例,更多細(xì)節(jié)和相關(guān)教程可參考腳本之家的其他文章2024-10-10
Vue3實(shí)現(xiàn)LuckSheet在線預(yù)覽Excel表格
在前端開發(fā)中預(yù)覽Excel文件是常見的需求之一,本文將介紹如何使用Vue.js框架以及兩個(gè)優(yōu)秀的Excel庫(kù)——LuckyExcel和Luckysheet,來(lái)實(shí)現(xiàn)Excel文件在線預(yù)覽功能,希望對(duì)大家有所幫助2023-11-11
解決vue 使用axios.all()方法發(fā)起多個(gè)請(qǐng)求控制臺(tái)報(bào)錯(cuò)的問題
這篇文章主要介紹了解決vue 使用axios.all()方法發(fā)起多個(gè)請(qǐng)求控制臺(tái)報(bào)錯(cuò)的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-11-11

