<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

        vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:09:41
        文檔

        vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼

        vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼:1.自定義 提示框 組件 src / components / Toast / index.js /** * 自定義 提示框( Toast )組件 */ var Toast = {}; var showToast = false, // 存儲(chǔ)toast顯示狀態(tài) showLoad = false, // 存儲(chǔ)loading顯示狀態(tài) toast
        推薦度:
        導(dǎo)讀vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼:1.自定義 提示框 組件 src / components / Toast / index.js /** * 自定義 提示框( Toast )組件 */ var Toast = {}; var showToast = false, // 存儲(chǔ)toast顯示狀態(tài) showLoad = false, // 存儲(chǔ)loading顯示狀態(tài) toast

        1.自定義 提示框 組件

        src / components / Toast / index.js

        /**
         * 自定義 提示框( Toast )組件
         */
        var Toast = {};
        var showToast = false, // 存儲(chǔ)toast顯示狀態(tài)
         showLoad = false, // 存儲(chǔ)loading顯示狀態(tài)
         toastVM = null, // 存儲(chǔ)toast vm
         loadNode = null; // 存儲(chǔ)loading節(jié)點(diǎn)元素
         
        Toast.install = function (Vue, options) {
         // 參數(shù)
         var opt = {
         defaultType: 'bottom',
         duration: '2500',
         wordWrap: false
         };
         for (var property in options) {
         opt[property] = options[property];
         }
         
         Vue.prototype.$toast = function (tips, type) {
         
         var curType = type ? type : opt.defaultType;
         var wordWrap = opt.wordWrap ? 'lx-word-wrap' : '';
         var style = opt.width ? 'style="width: ' + opt.width + '"' : '';
         var tmp = '<div v-show="show" :class="type" class="lx-toast ' + wordWrap + '" ' + style + '>{{tip}}</div>';
         
         if (showToast) {
         // 如果toast還在,則不再執(zhí)行
         return;
         }
         if (!toastVM) {
         var toastTpl = Vue.extend({
         data: function () {
         return {
         show: showToast,
         tip: tips,
         type: 'lx-toast-' + curType
         }
         },
         template: tmp
         });
         toastVM = new toastTpl()
         var tpl = toastVM.$mount().$el;
         document.body.appendChild(tpl);
         }
         toastVM.type = 'lx-toast-' + curType;
         toastVM.tip = tips;
         toastVM.show = showToast = true;
         
         setTimeout(function () {
         toastVM.show = showToast = false;
         }, opt.duration)
         };
         
         ['bottom', 'center', 'top'].forEach(function (type) {
         Vue.prototype.$toast[type] = function (tips) {
         return Vue.prototype.$toast(tips, type)
         }
         });
         
         Vue.prototype.$loading = function (tips, type) {
         if (type == 'close') {
         loadNode.show = showLoad = false;
         } else {
         if (showLoad) {
         // 如果loading還在,則不再執(zhí)行
         return;
         }
         var loadTpl = Vue.extend({
         data: function () {
         return {
         show: showLoad
         }
         },
         template: '<div v-show="show" class="lx-load-mark"><div class="lx-load-box"><div class="lx-loading"><div class="loading_leaf loading_leaf_0"></div><div class="loading_leaf loading_leaf_1"></div><div class="loading_leaf loading_leaf_2"></div><div class="loading_leaf loading_leaf_3"></div><div class="loading_leaf loading_leaf_4"></div><div class="loading_leaf loading_leaf_5"></div><div class="loading_leaf loading_leaf_6"></div><div class="loading_leaf loading_leaf_7"></div><div class="loading_leaf loading_leaf_8"></div><div class="loading_leaf loading_leaf_9"></div><div class="loading_leaf loading_leaf_10"></div><div class="loading_leaf loading_leaf_11"></div></div><div class="lx-load-content">' + tips + '</div></div></div>'
         });
         loadNode = new loadTpl();
         var tpl = loadNode.$mount().$el;
         
         document.body.appendChild(tpl);
         loadNode.show = showLoad = true;
         }
         };
         
         ['open', 'close'].forEach(function (type) {
         Vue.prototype.$loading[type] = function (tips) {
         return Vue.prototype.$loading(tips, type)
         }
         });
        }
         
        // 向外暴露接口
        module.exports = Toast;

        src / components / Toast / toast.css

        /**
         * Toast 樣式
         */
        .lx-toast {
         position: fixed;
         bottom: 100px;
         left: 50%;
         box-sizing: border-box;
         max-width: 80%;
         height: 40px;
         line-height: 20px;
         padding: 10px 20px;
         transform: translateX(-50%);
         -webkit-transform: translateX(-50%);
         text-align: center;
         z-index: 9999;
         font-size: 14px;
         color: #fff;
         border-radius: 5px;
         background: rgba(0, 0, 0, 0.7);
         animation: show-toast .5s;
         -webkit-animation: show-toast .5s;
         overflow: hidden;
         text-overflow: ellipsis;
         white-space: nowrap;
        }
         
        .lx-toast.lx-word-wrap {
         width: 80%;
         white-space: inherit;
         height: auto;
        }
         
        .lx-toast.lx-toast-top {
         top: 50px;
         bottom: inherit;
        }
         
        .lx-toast.lx-toast-center {
         top: 50%;
         margin-top: -20px;
         bottom: inherit;
        }
         
        @keyframes show-toast {
         from {
         opacity: 0;
         transform: translate(-50%, -10px);
         -webkit-transform: translate(-50%, -10px);
         }
         to {
         opacity: 1;
         transform: translate(-50%, 0);
         -webkit-transform: translate(-50%, 0);
         }
        }
         
        .lx-load-mark {
         position: fixed;
         left: 0;
         top: 0;
         width: 100%;
         height: 100%;
         z-index: 9999;
        }
         
        .lx-load-box {
         position: fixed;
         z-index: 3;
         width: 7.6em;
         min-height: 7.6em;
         top: 180px;
         left: 50%;
         margin-left: -3.8em;
         background: rgba(0, 0, 0, 0.7);
         text-align: center;
         border-radius: 5px;
         color: #FFFFFF;
        }
         
        .lx-load-content {
         margin-top: 64%;
         font-size: 14px;
        }
         
        .lx-loading {
         position: absolute;
         width: 0px;
         left: 50%;
         top: 38%;
        }
         
        .loading_leaf {
         position: absolute;
         top: -1px;
         opacity: 0.25;
        }
         
        .loading_leaf:before {
         content: " ";
         position: absolute;
         width: 9.14px;
         height: 3.08px;
         background: #d1d1d5;
         box-shadow: rgba(0, 0, 0, 0.0980392) 0px 0px 1px;
         border-radius: 1px;
         -webkit-transform-origin: left 50% 0px;
         transform-origin: left 50% 0px;
        }
         
        .loading_leaf_0 {
         -webkit-animation: opacity-0 1.25s linear infinite;
         animation: opacity-0 1.25s linear infinite;
        }
         
        .loading_leaf_0:before {
         -webkit-transform: rotate(0deg) translate(7.92px, 0px);
         transform: rotate(0deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_1 {
         -webkit-animation: opacity-1 1.25s linear infinite;
         animation: opacity-1 1.25s linear infinite;
        }
         
        .loading_leaf_1:before {
         -webkit-transform: rotate(30deg) translate(7.92px, 0px);
         transform: rotate(30deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_2 {
         -webkit-animation: opacity-2 1.25s linear infinite;
         animation: opacity-2 1.25s linear infinite;
        }
         
        .loading_leaf_2:before {
         -webkit-transform: rotate(60deg) translate(7.92px, 0px);
         transform: rotate(60deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_3 {
         -webkit-animation: opacity-3 1.25s linear infinite;
         animation: opacity-3 1.25s linear infinite;
        }
         
        .loading_leaf_3:before {
         -webkit-transform: rotate(90deg) translate(7.92px, 0px);
         transform: rotate(90deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_4 {
         -webkit-animation: opacity-4 1.25s linear infinite;
         animation: opacity-4 1.25s linear infinite;
        }
         
        .loading_leaf_4:before {
         -webkit-transform: rotate(120deg) translate(7.92px, 0px);
         transform: rotate(120deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_5 {
         -webkit-animation: opacity-5 1.25s linear infinite;
         animation: opacity-5 1.25s linear infinite;
        }
         
        .loading_leaf_5:before {
         -webkit-transform: rotate(150deg) translate(7.92px, 0px);
         transform: rotate(150deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_6 {
         -webkit-animation: opacity-6 1.25s linear infinite;
         animation: opacity-6 1.25s linear infinite;
        }
         
        .loading_leaf_6:before {
         -webkit-transform: rotate(180deg) translate(7.92px, 0px);
         transform: rotate(180deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_7 {
         -webkit-animation: opacity-7 1.25s linear infinite;
         animation: opacity-7 1.25s linear infinite;
        }
         
        .loading_leaf_7:before {
         -webkit-transform: rotate(210deg) translate(7.92px, 0px);
         transform: rotate(210deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_8 {
         -webkit-animation: opacity-8 1.25s linear infinite;
         animation: opacity-8 1.25s linear infinite;
        }
         
        .loading_leaf_8:before {
         -webkit-transform: rotate(240deg) translate(7.92px, 0px);
         transform: rotate(240deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_9 {
         -webkit-animation: opacity-9 1.25s linear infinite;
         animation: opacity-9 1.25s linear infinite;
        }
         
        .loading_leaf_9:before {
         -webkit-transform: rotate(270deg) translate(7.92px, 0px);
         transform: rotate(270deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_10 {
         -webkit-animation: opacity-10 1.25s linear infinite;
         animation: opacity-10 1.25s linear infinite;
        }
         
        .loading_leaf_10:before {
         -webkit-transform: rotate(300deg) translate(7.92px, 0px);
         transform: rotate(300deg) translate(7.92px, 0px);
        }
         
        .loading_leaf_11 {
         -webkit-animation: opacity-11 1.25s linear infinite;
         animation: opacity-11 1.25s linear infinite;
        }
         
        .loading_leaf_11:before {
         -webkit-transform: rotate(330deg) translate(7.92px, 0px);
         transform: rotate(330deg) translate(7.92px, 0px);
        }
         
        @-webkit-keyframes opacity-0 {
         0% {
         opacity: 0.25;
         }
         0.01% {
         opacity: 0.25;
         }
         0.02% {
         opacity: 1;
         }
         60.01% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.25;
         }
        }
         
        @-webkit-keyframes opacity-1 {
         0% {
         opacity: 0.25;
         }
         8.34333% {
         opacity: 0.25;
         }
         8.35333% {
         opacity: 1;
         }
         68.3433% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.25;
         }
        }
         
        @-webkit-keyframes opacity-2 {
         0% {
         opacity: 0.25;
         }
         16.6767% {
         opacity: 0.25;
         }
         16.6867% {
         opacity: 1;
         }
         76.6767% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.25;
         }
        }
         
        @-webkit-keyframes opacity-3 {
         0% {
         opacity: 0.25;
         }
         25.01% {
         opacity: 0.25;
         }
         25.02% {
         opacity: 1;
         }
         85.01% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.25;
         }
        }
         
        @-webkit-keyframes opacity-4 {
         0% {
         opacity: 0.25;
         }
         33.3433% {
         opacity: 0.25;
         }
         33.3533% {
         opacity: 1;
         }
         93.3433% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.25;
         }
        }
         
        @-webkit-keyframes opacity-5 {
         0% {
         opacity: 0.270958333333333;
         }
         41.6767% {
         opacity: 0.25;
         }
         41.6867% {
         opacity: 1;
         }
         1.67667% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.270958333333333;
         }
        }
         
        @-webkit-keyframes opacity-6 {
         0% {
         opacity: 0.375125;
         }
         50.01% {
         opacity: 0.25;
         }
         50.02% {
         opacity: 1;
         }
         10.01% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.375125;
         }
        }
         
        @-webkit-keyframes opacity-7 {
         0% {
         opacity: 0.479291666666667;
         }
         58.3433% {
         opacity: 0.25;
         }
         58.3533% {
         opacity: 1;
         }
         18.3433% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.479291666666667;
         }
        }
         
        @-webkit-keyframes opacity-8 {
         0% {
         opacity: 0.583458333333333;
         }
         66.6767% {
         opacity: 0.25;
         }
         66.6867% {
         opacity: 1;
         }
         26.6767% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.583458333333333;
         }
        }
         
        @-webkit-keyframes opacity-9 {
         0% {
         opacity: 0.687625;
         }
         75.01% {
         opacity: 0.25;
         }
         75.02% {
         opacity: 1;
         }
         35.01% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.687625;
         }
        }
         
        @-webkit-keyframes opacity-10 {
         0% {
         opacity: 0.791791666666667;
         }
         83.3433% {
         opacity: 0.25;
         }
         83.3533% {
         opacity: 1;
         }
         43.3433% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.791791666666667;
         }
        }
         
        @-webkit-keyframes opacity-11 {
         0% {
         opacity: 0.895958333333333;
         }
         91.6767% {
         opacity: 0.25;
         }
         91.6867% {
         opacity: 1;
         }
         51.6767% {
         opacity: 0.25;
         }
         100% {
         opacity: 0.895958333333333;
         }
        }

        2.全局引入

        main.js

        // 全局引入Toast
        import './components/Toast/toast.css';
        import Toast from './components/Toast/index';
        Vue.use(Toast);
        

        3.頁面調(diào)用

        Toast.vue

        <!-- 提示框 -->
        
        <template>
        
         <div>
        
         <!-- 標(biāo)題欄 -->
        
         <mt-header title= "提示框" >
        
         <router-link to= "/" slot= "left" >
        
         <mt-button icon= "back" >返回</mt-button>
        
         </router-link>
        
         </mt-header>
        
         <!-- 內(nèi)容 -->
        
         <button @click= "openTop()" >top</button>
        
         <button @click= "openCenter()" >center</button>
        
         <button @click= "openBottom()" >bottom</button>
        
         <button @click= "openLoading()" >loading</button>
        
         </div>
        
        </template>
        
        <script>
        
         export default {
        
         name: 'Toast' ,
        
         data(){
        
         return {
        
         //
        
         }
        
         },
        
         methods:{
        
         openTop(){
        
         this .$toast.top( 'top' );
        
         },
        
         openCenter(){
        
         this .$toast.center( 'center' );
        
         },
        
         openBottom(){
        
         this .$toast( 'bottom' ); // or this.$toast.bottom('bottom');
        
         },
        
         openLoading(){
        
         this .$loading( 'loading...' );
        
         let self = this ;
        
         setTimeout( function () {
        
         self.closeLoading()
        
         }, 2000)
        
         },
        
         closeLoading(){
        
         this .$loading.close();
        
         }
        
         }
        
         }
        
        </script>
        
        <style lang= "less" scoped>
         //
        </style>

        4.效果圖

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼

        vue 自定義提示框(Toast)組件的實(shí)現(xiàn)代碼:1.自定義 提示框 組件 src / components / Toast / index.js /** * 自定義 提示框( Toast )組件 */ var Toast = {}; var showToast = false, // 存儲(chǔ)toast顯示狀態(tài) showLoad = false, // 存儲(chǔ)loading顯示狀態(tài) toast
        推薦度:
        標(biāo)簽: VUE 代碼 組件
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 免费人成年激情视频在线观看| 一级毛片免费不卡在线| 香蕉视频在线观看免费国产婷婷| 亚洲人成人网毛片在线播放| 精品国产无限资源免费观看| 亚洲啪啪免费视频| 免费毛片a在线观看67194| 亚洲资源最新版在线观看| 免费中文熟妇在线影片| 亚洲a∨国产av综合av下载| 国产成人aaa在线视频免费观看 | 亚洲永久网址在线观看| 女人18毛片水最多免费观看| 亚洲欧美日韩久久精品| 全亚洲最新黄色特级网站| eeuss在线兵区免费观看| 久久久久无码精品亚洲日韩| 120秒男女动态视频免费| 久久精品国产亚洲av麻豆蜜芽| 在线观看成人免费视频| 免费看一级一级人妻片| 精品亚洲综合久久中文字幕| 啦啦啦完整版免费视频在线观看 | 亚洲综合在线观看视频| 最新中文字幕免费视频| 国产在亚洲线视频观看| 亚洲色欲一区二区三区在线观看| 2022久久国产精品免费热麻豆| 亚洲色偷偷色噜噜狠狠99| 亚洲日本一区二区三区在线不卡| 国产日韩一区二区三免费高清| 激情综合亚洲色婷婷五月APP| 在线观看免费精品国产| a毛片全部免费播放| 亚洲最大天堂无码精品区| 亚洲精品WWW久久久久久| 777爽死你无码免费看一二区| 亚洲成熟丰满熟妇高潮XXXXX| 好看的电影网站亚洲一区| 午夜色a大片在线观看免费| 亚洲第一视频在线观看免费|