最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue組件系列開發(fā)之模態(tài)框

 更新時間:2019年04月18日 15:06:43   作者:Echi灬丨無痕  
這篇文章主要介紹了Vue組件系列開發(fā)之模態(tài)框,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下

項目基礎工程文件是使用vue-cli3.0搭建的,這里不過多介紹。開發(fā)Vue組件系列之模態(tài)框,主要有標題、內(nèi)容、定時器、按鈕文案、按鈕事件回調(diào)、遮罩層這些可配置項。本次開發(fā)得組件是本系列的第一個組件,后期也會有更多系列教程推出。

使用命令行

$ Vue create echi-modal
$ cd echi-modal
$ npm install
$ npm run serve
$ npm run build
$ npm run lint

添加vue.config.js文件,配置如下

const path = require("path");

function resolve(dir) {
 return path.join(__dirname, dir);
}

module.exports = {
 // 基本路徑
 publicPath: "./",
 // eslint-loader 是否在保存的時候檢查
 lintOnSave: false,
 // webpack配置
 // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
 chainWebpack: config => {
 config.resolve.alias
  .set("@", resolve("src"))
 },
 // 生產(chǎn)環(huán)境是否生成 sourceMap 文件
 productionSourceMap: false,
 // css相關配置
 css: {
 // 是否使用css分離插件 ExtractTextPlugin
 extract: true,
 // 開啟 CSS source maps?
 sourceMap: false,
 // css預設器配置項
 loaderOptions: {},
 // 啟用 CSS modules for all css / pre-processor files.
 modules: false
 },
 // use thread-loader for babel & TS in production build
 // enabled by default if the machine has more than 1 cores
 parallel: require("os").cpus().length > 1,
 devServer: {
 port: 9595, // 端口號
 open: true, // 自動開啟瀏覽器
 compress: true, // 開啟壓縮
 overlay: {
  warnings: true,
  errors: true
 }
 }
};

項目結(jié)構

├── src       # 項目源碼。開發(fā)的時候代碼寫在這里。
│ ├── components     # 組件目錄
| | |--EchiModal    # 模態(tài)框組件
│ ├── App.vue     # 項目根視圖
│ ├── main.js     # 程序主入口

部分截圖

modal組件模板

使用 transition 可以為組件添加動效;對應的組件模板內(nèi)容如下

<template>
 <transition name="toggle">
 <section class="modal" v-show="visible">
  <div class="modal-mask" v-show="showMask" @click="clickMask"></div>
  <section class="modal-content modal-center" :style="contentStyle">
  <header class="modal-header" :class="{ 'modal-plain': plain }" v-if="showHeader">
   <slot name="header">{{ title }}</slot>
   <span class="closed" v-if="showClose" @click.stop="onClose">
   關閉
   </span>
  </header>
  <main class="modal-body">
   <slot>
   <div class="text-tips">{{ text }}</div>
   </slot>
  </main>
  <footer class="modal-footer" v-if="showFooter">
   <slot name="footer">
   <button class="modal-btn modal-btn-primary" @click.stop="onConfirm">
    {{ confirmBtnText }}
   </button>
   <button class="modal-btn modal-btn-default" @click.stop="onClose">
    {{ cancelBtnText }}
   </button>
   </slot>
  </footer>
  </section>
 </section>
 </transition>
</template>

添加組件屬性及操作方法

添加組件的屬性,其中duration屬性如果設定的數(shù)值小于10,則會乘以1000;否則按傳遞的數(shù)值計算

<script>
 export default {
 name: "EchiModal",
 props: {
  visible: {
  type: Boolean,
  default: false
  },
  title: {
  type: String,
  default: "標題"
  },
  text: {
  type: String,
  default: "提示信息"
  },
  tinyBar: {
  type: Boolean,
  default: false
  },
  confirmBtnText: {
  type: String,
  default: "確定"
  },
  cancelBtnText: {
  type: String,
  default: "返回"
  },
  contentStyle: {
  type: Object,
  default: () => {}
  },
  showClose: {
  type: Boolean,
  default: true
  },
  plain: {
  type: Boolean,
  default: false
  },
  showHeader: {
  type: Boolean,
  default: true
  },
  showFooter: {
  type: Boolean,
  default: true
  },
  showMask: {
  type: Boolean,
  default: true
  },
  onMask: {
  type: Boolean,
  default: false
  },
  duration: {
  type: Number,
  default: 0
  }
 },
 watch: {
  visible(nv) {
  if (nv) {
   this.closeTimerHandle()
  }
  }
 },
 data() {
  return {
  closeTimer: null,
  }
 },
 methods: {
  onClose() {
  this.$emit("on-close");
  this.hide();
  },
  onConfirm() {
  this.$emit("on-confirm");
  },
  hide() {
  this.$emit("update:visible", false);
  this.$emit("on-closed");
  clearTimeout(this.closeTimer);
  this.closeTimer = null;
  },
  clickMask() {
  if (this.onMask && this.showMask) {
   this.hide();
  }
  },
  closeTimerHandle() {
  try {
   if (this.duration <= 0) {
   return;
   }
   const duration = (this.duration < 10) ? (this.duration * 1000) : this.duration;
   clearTimeout(this.closeTimer);
   this.closeTimer = setTimeout(() => {
   this.onClose();
   }, duration);
  } catch (e) {
   console.log(e)
  }
  }
 }
 };
</script>

添加樣式聲明

<style scoped lang="scss">
 *,
 :after,
 :before {
 box-sizing: border-box;
 outline: none;
 -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
 }

 $color-tips: #1ab394;
 $color-text: rgba(255, 255, 255, 0.6);
 $color-info: #ff9900;
 $color-default: #ccc;

 .modal {
 display: block;
 width: 100%;
 height: 100%;
 position: fixed;
 top: 0;
 left: 0;
 z-index: 99;

 .modal-mask {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
 }

 .modal-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
 }

 .modal-content {
  display: flex;
  flex-direction: column;
  min-width: 360px;
  box-shadow: 0 1px 8px 0 rgba(0, 30, 24, 0.05);
  background-color: #fff;
  border-radius: 6px;
  overflow: hidden;
 }

 .modal-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  font-size: 18px;
  padding: 0 20px;
  font-weight: 500;
  color: #fff;
  background-color: $color-tips;
  z-index: 9999;

  .closed {
  position: absolute;
  top: 50%;
  right: 0;
  font-size: 12px;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
  transform: translateY(-50%);
  }

  &.modal-plain {
  background-color: rgba(245,
   245,
   245,
   1);
  color: $color-tips;

  .closed {
   color: $color-info;
  }
  }
 }

 .modal-body {
  display: block;
  flex: 1;
  background-color: #fff;
  overflow: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
 }

 .modal-footer {
  display: block;
  width: 100%;
  padding: 20px 30px;
  text-align: center;
  background-color: #fff;

  .modal-btn {
  width: 80px;

  +.modal-btn {
   margin-left: 8px;
  }
  }
 }
 }

 .text-tips {
 display: block;
 width: 100%;
 font-size: 16px;
 text-align: center;
 color: #333;
 padding: 40px 60px;
 }

 .modal-btn {
 display: inline-flex;
 padding: 0 12;
 margin: 0;
 align-items: center;
 justify-content: center;
 font-size: 14px;
 font-weight: 400;
 height: 32px;
 text-align: center;
 white-space: nowrap;
 touch-action: manipulation;
 -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
 cursor: pointer;
 user-select: none;
 background-image: none;
 text-decoration: none;
 border: 1px solid transparent;
 border-radius: 4px;
 transition: all .3s ease;

 &:link,
 &:visited,
 &:hover,
 &:active {
  text-decoration: none;
 }
 }

 .modal-btn-default {
 background-color: $color-default;
 color: #fff;

 &:link {
  color: #fff;
  background-color: $color-default;
 }

 &:visited {
  color: #fff;
  background-color: $color-default;
 }

 &:hover {
  color: #fff;
  background-color: rgba(170, 170, 170, .85);
 }

 &:active {
  color: #fff;
  background-color: $color-default;
 }

 &[plain] {
  background-color: #fff;
  color: $color-default;
  border: 1px solid $color-default;
 }
 }

 .modal-btn-primary {
 background-color: $color-tips;
 color: #fff;

 &:link {
  color: #fff;
  background-color: $color-tips;
 }

 &:visited {
  color: #fff;
  background-color: $color-tips;
 }

 &:hover {
  color: #fff;
  background-color: rgba(26, 179, 148, 0.85);
 }

 &:active {
  color: #fff;
  background-color: $color-tips;
 }

 &[plain] {
  background-color: #fff;
  color: $color-tips;
  border: 1px solid $color-tips;
 }
 }

 .toggle-enter,
 .toggle-leave-active {
 opacity: 0;
 transform: translatey(-10px);
 }

 .toggle-enter-active,
 .toggle-leave-active {
 transition: all ease .2s;
 }
</style>

使用

<template>
 <div id="app">
 <img alt="Vue logo" src="./assets/logo.png" />
 <div>
  <button @click.stop="showModel_0 = true">
  顯示默認樣式
  </button>
  <button @click.stop="showModel_1 = true">
  顯示素樣式
  </button>
  <button @click.stop="showModel_2 = true">
  修改提示語
  </button>
  <button @click.stop="showModel_3 = true">
  自定義內(nèi)容
  </button>
  <button @click.stop="showModel_4 = true">
  去除Footer
  </button>
  <button @click.stop="showModel_5 = true">
  去除Header
  </button>
  <button @click.stop="showModel_6 = true">
  設置3秒后自動關閉
  </button>
 </div>
 <EchiModal :visible.sync="showModel_0" title="顯示默認樣式"></EchiModal>
 <EchiModal :visible.sync="showModel_1" title="顯示素樣式" plain></EchiModal>
 <EchiModal :visible.sync="showModel_2" title="修改提示語" text="哈哈哈哈哈,我把提示信息修改了"></EchiModal>
 <EchiModal :visible.sync="showModel_3" title="自定義內(nèi)容" :contentStyle="{width: '600px'}">
  <img alt="Vue logo" src="./assets/logo.png" />
 </EchiModal>
 <EchiModal :visible.sync="showModel_4" title="去除Footer" :showFooter="false"></EchiModal>
 <EchiModal :visible.sync="showModel_5" title="去除Header" :showHeader="false"></EchiModal>
 <EchiModal :visible.sync="showModel_6" title="設置3秒后自動關閉" :duration="3"></EchiModal>
 </div>
</template>

<script>
 import EchiModal from "./components/EchiModal.vue";

 export default {
 name: "app",
 components: {
  EchiModal
 },
 data() {
  return {
  showModel_0: false,
  showModel_1: false,
  showModel_2: false,
  showModel_3: false,
  showModel_4: false,
  showModel_5: false,
  showModel_6: false,
  }
 }
 };
</script>

感謝那您的觀看,以上就是我為大家?guī)淼哪B(tài)框組件,本文同步更新于我的github點擊前往。

相關文章

  • Vue利用AJAX請求獲取XML文件數(shù)據(jù)的操作方法

    Vue利用AJAX請求獲取XML文件數(shù)據(jù)的操作方法

    在現(xiàn)代Web開發(fā)中,從前端框架到后端API的交互是必不可少的一部分,Vue.js作為一個輕量級且功能強大的前端框架,支持多種方式與服務器通信,從而獲取或發(fā)送數(shù)據(jù),本文將詳細介紹如何在Vue.js項目中使用AJAX請求來獲取XML格式的數(shù)據(jù),需要的朋友可以參考下
    2024-09-09
  • vue完成項目后,打包成靜態(tài)文件的方法

    vue完成項目后,打包成靜態(tài)文件的方法

    今天小編就為大家分享一篇vue完成項目后,打包成靜態(tài)文件的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue實現(xiàn)圖片下載點擊按鈕彈出本地窗口選擇自定義保存路徑功能

    vue實現(xiàn)圖片下載點擊按鈕彈出本地窗口選擇自定義保存路徑功能

    vue前端實現(xiàn)前端下載,并實現(xiàn)點擊按鈕彈出本地窗口,選擇自定義保存路徑,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-12-12
  • Vue腳手架編寫試卷頁面功能

    Vue腳手架編寫試卷頁面功能

    腳手架是一種用于快速開發(fā)Vue項目的系統(tǒng)架構,這篇文章主要介紹了Vue腳手架實現(xiàn)試卷頁面功能,通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • VUE注冊全局組件和局部組件過程解析

    VUE注冊全局組件和局部組件過程解析

    這篇文章主要介紹了VUE注冊全局組件和局部組件過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-10-10
  • 關于vue-router路由的傳參方式params query

    關于vue-router路由的傳參方式params query

    這篇文章主要介紹了關于vue-router路由的傳參方式params query,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue3實現(xiàn)自定義指令攔截點擊事件的示例代碼

    Vue3實現(xiàn)自定義指令攔截點擊事件的示例代碼

    某些應用場景會給點擊事件添加權限,不存在權限就攔截點擊事件,有權限就繼續(xù)正常觸發(fā)點擊事件。這樣的效果是如何實現(xiàn)的呢,本文就來和大家詳細講講
    2023-02-02
  • 關于在Vue中import和require的用法分析

    關于在Vue中import和require的用法分析

    在Vue項目中,我們經(jīng)常需要引入外部的模塊或文件,這時候就會用到import和require這兩個關鍵字,本文將詳細分析它們的用法,并提供具體的代碼實例和解釋,需要的朋友可以參考下
    2023-06-06
  • vue實現(xiàn)在v-html的html字符串中綁定事件

    vue實現(xiàn)在v-html的html字符串中綁定事件

    今天小編就為大家分享一篇vue實現(xiàn)在v-html的html字符串中綁定事件,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • vuejs指令詳解

    vuejs指令詳解

    本文介紹了vuejs指令的相關知識,具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02

最新評論

永安市| 桐梓县| 鱼台县| 公主岭市| 宜丰县| 安平县| 潼南县| 吉隆县| 肃宁县| 东乡| 盐池县| 天峨县| 瑞昌市| 巴南区| 建瓯市| 耒阳市| 正镶白旗| 中山市| 崇信县| 信阳市| 台东市| 四平市| 东阳市| 察雅县| 包头市| 东安县| 灌阳县| 盘锦市| 吉林省| 青岛市| 芜湖市| 兰西县| 石楼县| 台东市| 渭南市| 永胜县| 南阳市| 锡林浩特市| 饶河县| 宁陕县| 普宁市|