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

首頁 > 編程 > JavaScript > 正文

vue組件之Alert的實現代碼

2019-11-19 15:09:28
字體:
來源:轉載
供稿:網友

前言

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

Alert

用于頁面中展示重要的提示信息。

templat模板結構

<template> <div v-show="visible" class="Alert">  <i v-show="closable" class="iconhandle close" @click="close"></i>  <slot></slot> </div></template>

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

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

<transition name="alert-fade"></transition>

script

export default { name: 'Alert', props: {  closable: {   type: Boolean,   default: true  },  show: {   type: Boolean,   default: true,   twoWay: true  },  type: {   type: String,   default: 'info'  } }, data() {  return {   visible: this.show  }; }, methods: {  close() {   this.visible = false;   this.$emit('update:show', false);   this.$emit('close');  } }};
  • name: 組件的名字
  • props: 屬性
  • methods: 方法

點擊關閉 向外暴露2個事件

使用

import Alert from './Alert.vue'Alert.install = function(Vue){  Vue.component('Alert', Alert);}export default Alert
<Alert :closable="false"> 這是一個不能關閉的alert</Alert><Alert> 這是一個可以關閉的alert</Alert>

Attribute

參數 說明 類型 可選值 默認值
closable 是否可關閉 boolean true
show 是否顯示 boolean true

Event

事件名稱 說明 回調參數
update:show 關閉時觸發,是否顯示false false
close 關閉時觸發

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保亭| 夏津县| 清流县| 安阳县| 元阳县| 西峡县| 通河县| 高要市| 富川| 沾化县| 龙山县| 长子县| 高安市| 陆丰市| 贺州市| 醴陵市| 五大连池市| 阜南县| 永济市| 安阳市| 临城县| 恩平市| 景东| 长汀县| 洪雅县| 宝山区| 克东县| 普兰店市| 武山县| 翼城县| 囊谦县| 苗栗市| 甘孜| 青川县| 信丰县| 江源县| 高淳县| 平阳县| 阳春市| 蕲春县| 新晃|