<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關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題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關鍵字專題關鍵字專題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
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Vue組件系列開發之模態框

        來源:懂視網 責編:小采 時間:2020-11-27 21:58:29
        文檔

        Vue組件系列開發之模態框

        Vue組件系列開發之模態框:項目基礎工程文件是使用vue-cli3.0搭建的,這里不過多介紹。開發Vue組件系列之模態框,主要有標題、內容、定時器、按鈕文案、按鈕事件回調、遮罩層這些可配置項。本次開發得組件是本系列的第一個組件,后期也會有更多系列教程推出。 使用命令行 $ Vue
        推薦度:
        導讀Vue組件系列開發之模態框:項目基礎工程文件是使用vue-cli3.0搭建的,這里不過多介紹。開發Vue組件系列之模態框,主要有標題、內容、定時器、按鈕文案、按鈕事件回調、遮罩層這些可配置項。本次開發得組件是本系列的第一個組件,后期也會有更多系列教程推出。 使用命令行 $ Vue

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

        使用命令行

        $ 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"))
         },
         // 生產環境是否生成 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
         }
         }
        };

        項目結構

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

        部分截圖

        modal組件模板

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

        <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屬性如果設定的數值小于10,則會乘以1000;否則按傳遞的數值計算

        <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">
         自定義內容
         </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="自定義內容" :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>

        感謝那您的觀看,

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Vue組件系列開發之模態框

        Vue組件系列開發之模態框:項目基礎工程文件是使用vue-cli3.0搭建的,這里不過多介紹。開發Vue組件系列之模態框,主要有標題、內容、定時器、按鈕文案、按鈕事件回調、遮罩層這些可配置項。本次開發得組件是本系列的第一個組件,后期也會有更多系列教程推出。 使用命令行 $ Vue
        推薦度:
        標簽: VUE 開發 系列
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 免费无码VA一区二区三区| 成人免费无码H在线观看不卡| 波多野结衣免费在线观看| 国产精品亚洲成在人线| 丁香花在线观看免费观看图片| 亚洲熟妇无码八AV在线播放| a级在线免费观看| 亚洲av色福利天堂| 无码国产精品一区二区免费式影视 | 精品亚洲一区二区三区在线观看 | 久久午夜免费鲁丝片| 亚洲高清在线mv| 无码国产精品一区二区免费式直播| 亚洲www77777| 免费一级大黄特色大片| 国产特黄一级一片免费| 亚洲精品在线播放视频| 美女黄网站人色视频免费国产| 美女的胸又黄又www网站免费| 久久久久亚洲AV成人网人人网站 | 久草福利资源网站免费| 亚洲性一级理论片在线观看| 麻豆精品国产免费观看| 国产精品免费一区二区三区| 亚洲黄色网站视频| 国产精品深夜福利免费观看| 在线观看片免费人成视频播放| 亚洲黄色片免费看| 国产性生交xxxxx免费| 成人自慰女黄网站免费大全| 亚洲日产2021三区在线| 免费一级毛片在级播放| 97人妻精品全国免费视频| 亚洲一区二区三区久久久久| 亚洲精品久久久www| 91制片厂制作传媒免费版樱花| 亚洲av无码专区首页| 亚洲一区二区三区高清| 免费萌白酱国产一区二区| 午夜视频免费在线观看| 久久亚洲中文字幕无码|