首頁 > web前端 > js教程 > 主體

vue組件之Alert詳解

小云云
發布: 2018-01-15 13:27:11
原創
10665 人瀏覽過

本文主要介紹了vue組件之Alert的實作程式碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟著小編過來看看吧,希望能幫助大家。

前言

本文主要Alert 元件的大致框架, 提供少量可設定選項。 旨在大致提供思路

Alert

#用於頁面中展示重要的提示訊息。

templat模板結構


#
<template>
 <p v-show="visible" class="Alert">
  <i v-show="closable" class="iconhandle close" @click="close"></i>
  <slot></slot>
 </p>
</template>
登入後複製

大致結構alert框,icon圖標, slot插值(其他樣式顏色選項. ..)

如果需要動畫可以在外層包上Vue內建元件transition


#
<transition name="alert-fade">
</transition>
登入後複製

script


export default {
 name: &#39;Alert&#39;,

 props: {
  closable: {
   type: Boolean,
   default: true
  },
  show: {
   type: Boolean,
   default: true,
   twoWay: true
  },
  type: {
   type: String,
   default: &#39;info&#39;
  }
 },
 data() {
  return {
   visible: this.show
  };
 },
 methods: {
  close() {
   this.visible = false;
   this.$emit(&#39;update:show&#39;, false);
   this.$emit(&#39;close&#39;);
  }
 }
};
登入後複製
  • name: 元件的名稱

  • ##props: 屬性

  • ##methods: 方法
  • 點擊關閉向外暴露2個事件


使用


##
import Alert from &#39;./Alert.vue&#39;

Alert.install = function(Vue){
  Vue.component(&#39;Alert&#39;, Alert);
}
export default Alert
登入後複製


<Alert :closable="false">
 这是一个不能关闭的alert
</Alert>
<Alert>
 这是一个可以关闭的alert
</Alert>
登入後複製


Attribute

參數說明類型可選值預設值#closable是否可關閉boolean—true#show是否顯示boolean—true

Event

#事件名稱說明回呼參數#update:show關閉時觸發,是否顯示falsefalseclose關閉時觸發—


###################相關推薦:############JavaScript中alert()所使用的注意事項############js中除了alert,還有哪些提示方法### #########javascript中alert()與console.log()的差異#######

以上是vue組件之Alert詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!