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

寫(xiě)一個(gè)Vue Popup組件

 更新時(shí)間:2019年02月25日 09:46:57   作者:邱鴻彬  
這篇文章主要介紹了寫(xiě)一個(gè)Vue Popup組件,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

組件長(zhǎng)這樣

主要有標(biāo)題、內(nèi)容、按鈕個(gè)數(shù)、按鈕顏色、按鈕文案這些可配置項(xiàng)

期望的調(diào)用方式一

不需要等待用戶(hù)二次確認(rèn)

import Modal from 'common/components/modal'

handleModal() {
 Modal({
  title: '賺取收益?',
  content: '根據(jù)您的授權(quán)金額和計(jì)息天數(shù)計(jì)算得出(還未到賬)。實(shí)際以到賬金額為準(zhǔn)。',
  confirmText: '我知道了'
 })
}

期望的調(diào)用方式二

需要等待用戶(hù)二次確認(rèn)

import Modal from 'common/components/modal'

async handleModal() {
 await Modal({
  title: '確定現(xiàn)在申請(qǐng)結(jié)束嗎?',
  content: '申請(qǐng)后預(yù)計(jì)1-5個(gè)工作日可退出',
  cancelColor: '#ff7400',
  confirmColor: '#000',
  showCancel: true
 })
}

模板長(zhǎng)這樣

common/components/modal/modal.vue

這里用 transition 來(lái)包裹動(dòng)畫(huà),填好配置參數(shù)就行了

handleConfirm() 二次確認(rèn)事件我們不放這里實(shí)現(xiàn),具體原因后面會(huì)講
<template>
 <transition name="modal-pop">

  <div class="wrap"
     v-show="visible">

   <div class="modal">

    <h3>{{ title }}</h3>

    <p>{{ content }}</p>

    <div class="btns">
     <span v-if="showCancel"
        @click="visible = false"
        :style="`color: ${cancelColor}`">{{ cancelText }}</span>
     <span @click="handleConfirm()"
        :style="`color: ${confirmColor}`">{{ confirmText }}</span>
    </div>

   </div>

  </div>

 </transition>
</template>

<style lang="less">
@import './modal.less';
</style>

定義好 props 參數(shù)列表,visible 作為組件內(nèi)部狀態(tài)控制彈框打開(kāi)關(guān)閉

export default {
 props: [
  'title',
  'content',
  'showCancel',
  'cancelColor',
  'cancelText',
  'confirmText',
  'confirmColor'
 ],

 data() {
  return {
   visible: false
  }
 }
}

組件包裝

common/components/modal/index.js

先利用 vue 的 extend 拿到剛編寫(xiě)的模板

import Vue from 'vue'

const ModalConstructor = Vue.extend(require('./modal.vue'))

const Modal = (opts = {}) => {
 let _m = new ModalConstructor({ el: document.createElement('div') })
}

export default Modal

配置好默認(rèn)參數(shù),并將 visible 狀態(tài)打開(kāi)以顯示彈框,最終插入頁(yè)面

import Vue from 'vue'

const ModalConstructor = Vue.extend(require('./modal.vue'))

const Modal = (opts = {}) => {
 let _m = new ModalConstructor({ el: document.createElement('div') })

 _m.title = opts.title || '提示'
 _m.content = opts.content || ''
 _m.showCancel = opts.showCancel || false
 _m.cancelText = opts.cancelText || '取消'
 _m.cancelColor = opts.cancelColor || '#000'
 _m.confirmText = opts.confirmText || '確定'
 _m.confirmColor = opts.confirmColor || '#ff7400'
 _m.visible = true

 document.body.appendChild(_m.$el)
}

export default Modal

用戶(hù)點(diǎn)擊二次確認(rèn)事件后,為了方便組件外部捕捉,這里使用 Promise 包裝回調(diào)事件

這樣 handleConfirm() 放在這里實(shí)現(xiàn)是不是就方便很多了
import Vue from 'vue'

const ModalConstructor = Vue.extend(require('./modal.vue'))

const Modal = (opts = {}) => {
 let _m = new ModalConstructor({ el: document.createElement('div') })

 _m.title = opts.title || '提示'
 _m.content = opts.content || ''
 _m.showCancel = opts.showCancel || false
 _m.cancelText = opts.cancelText || '取消'
 _m.cancelColor = opts.cancelColor || '#000'
 _m.confirmText = opts.confirmText || '確定'
 _m.confirmColor = opts.confirmColor || '#ff7400'
 _m.visible = true

 document.body.appendChild(_m.$el)

 return new Promise(resolve => {
  return (_m.handleConfirm = () => {
   _m.visible = false
   resolve()
  })
 })
}

export default Modal

最終長(zhǎng)這樣

import Modal from 'common/components/modal'

async handleModal() {
 await Modal({
  title: '確定現(xiàn)在申請(qǐng)結(jié)束嗎?',
  content: '申請(qǐng)后預(yù)計(jì)1-5個(gè)工作日可退出',
  cancelColor: '#ff7400',
  confirmColor: '#000',
  showCancel: true
 })

 console.log('用戶(hù)確認(rèn)了!')
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

  • Vue3中Teleport的用法小結(jié)

    Vue3中Teleport的用法小結(jié)

    Teleport是一個(gè)內(nèi)置組件,它可以將一個(gè)組件內(nèi)部的一部分模板傳送到該組件的 DOM 結(jié)構(gòu)外層的位置去,本文主要介紹了Vue3中Teleport用法小結(jié),感興趣的可以了解一下
    2025-04-04
  • Vue-CLI3.x 自動(dòng)部署項(xiàng)目至服務(wù)器的方法步驟

    Vue-CLI3.x 自動(dòng)部署項(xiàng)目至服務(wù)器的方法步驟

    本教程講解的是 Vue-CLI 3.x 腳手架搭建的vue項(xiàng)目, 利用scp2自動(dòng)化部署到靜態(tài)文件服務(wù)器 Nginx,感興趣的可以了解一下
    2021-11-11
  • vue實(shí)現(xiàn)動(dòng)態(tài)控制表格列的顯示隱藏

    vue實(shí)現(xiàn)動(dòng)態(tài)控制表格列的顯示隱藏

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)動(dòng)態(tài)控制表格列的顯示隱藏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Vue.js每天必學(xué)之指令系統(tǒng)與自定義指令

    Vue.js每天必學(xué)之指令系統(tǒng)與自定義指令

    Vue.js每天必學(xué)之指令系統(tǒng)與自定義指令,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • 解決新建一個(gè)vue項(xiàng)目過(guò)程中遇到的問(wèn)題

    解決新建一個(gè)vue項(xiàng)目過(guò)程中遇到的問(wèn)題

    這篇文章主要介紹了解決新建一個(gè)vue項(xiàng)目過(guò)程中遇到的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-10-10
  • Vue非父子組件之間的通信方式詳解

    Vue非父子組件之間的通信方式詳解

    在實(shí)際業(yè)務(wù)中,除了父子組件通信外,還有很多非父子組件通信的場(chǎng)景,下面這篇文章主要給大家介紹了關(guān)于Vue非父子組件之間的通信方式,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • 基于Vue.js的表格分頁(yè)組件

    基于Vue.js的表格分頁(yè)組件

    這篇文章主要為大家詳細(xì)介紹了基于Vue.js的表格分頁(yè)組件使用方法,了解了Vue.js的特點(diǎn),感興趣的朋友可以參考一下
    2016-05-05
  • vue-dialog的彈出層組件

    vue-dialog的彈出層組件

    這篇文章主要為大家詳細(xì)介紹了vue-dialog的彈出層組件,可以通過(guò)npm引用的組件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • iview給radio按鈕組件加點(diǎn)擊事件的實(shí)例

    iview給radio按鈕組件加點(diǎn)擊事件的實(shí)例

    下面小編就為大家?guī)?lái)一篇iview給radio按鈕組件加點(diǎn)擊事件的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • vue中數(shù)組加Key方式

    vue中數(shù)組加Key方式

    這篇文章主要介紹了vue中數(shù)組加Key方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03

最新評(píng)論

巴彦淖尔市| 临夏市| 姜堰市| 黄平县| 莲花县| 屏东市| 突泉县| 元氏县| 阿鲁科尔沁旗| 宣武区| 红桥区| 佛教| 泗洪县| 岱山县| 江都市| 吉林市| 临汾市| 左贡县| 开远市| 台州市| 车致| 沐川县| 铅山县| 东丰县| 永德县| 龙口市| 永年县| 靖西县| 汾阳市| 嘉鱼县| 当涂县| 且末县| 漳州市| 遵义县| 新蔡县| 刚察县| 六安市| 黔江区| 杭州市| 南部县| 张家川|