国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue的全局提示框組件實例代碼

2019-11-19 14:17:41
字體:
來源:轉載
供稿:網友

這篇文章給大家介紹一個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 = {};// 注冊ToastToast.install = function (Vue) {  // 生成一個Vue的子類  // 同時這個子類也就是組件  const ToastConstructor = Vue.extend(ToastComponent)  // 生成一個該子類的實例  const instance = new ToastConstructor();  // 將這個實例掛載在我創建的div上  // 并將此div加入全局掛載點內部  instance.$mount(document.createElement('div'))  document.body.appendChild(instance.$el)  // 通過Vue的原型注冊一個方法  // 讓所有實例共享這個方法   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");

總結

以上所述是小編給大家介紹的vue的全局提示框組件實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁安市| 潢川县| 临安市| 泰宁县| 门头沟区| 日土县| 吴堡县| 玉屏| 福州市| 夏河县| 林西县| 滕州市| 达拉特旗| 彭阳县| 噶尔县| 滦平县| 全南县| 赫章县| 桃园市| 济宁市| 右玉县| 无锡市| 望谟县| 龙州县| 昌宁县| 吉安市| 神木县| 惠水县| 四子王旗| 汉川市| 阳城县| 宣城市| 玛曲县| 玉田县| 宜都市| 南漳县| 呼伦贝尔市| 长宁县| 连平县| 友谊县| 华池县|