欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

寫一個(gè)Vue Popup組件

 更新時(shí)間:2019年02月25日 09:46:57   作者:邱鴻彬  
這篇文章主要介紹了寫一個(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)用方式一

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

import Modal from 'common/components/modal'

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

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

需要等待用戶二次確認(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)畫,填好配置參數(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)控制彈框打開關(guān)閉

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

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

組件包裝

common/components/modal/index.js

先利用 vue 的 extend 拿到剛編寫的模板

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)打開以顯示彈框,最終插入頁(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

用戶點(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('用戶確認(rèn)了!')
}

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

您可能感興趣的文章:

相關(guān)文章

  • Vue自定義指令獲取不到參數(shù)的原因及解決

    Vue自定義指令獲取不到參數(shù)的原因及解決

    這篇文章主要介紹了Vue自定義指令獲取不到參數(shù)的原因及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue實(shí)現(xiàn)分頁(yè)欄效果

    vue實(shí)現(xiàn)分頁(yè)欄效果

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)分頁(yè)欄效果,分頁(yè)欄設(shè)計(jì)的步驟與實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • Vue v-model實(shí)現(xiàn)案例介紹

    Vue v-model實(shí)現(xiàn)案例介紹

    v-model就是vue的雙向綁定的指令,能將頁(yè)面上控件輸入的值同步更新到相關(guān)綁定的data屬性,也會(huì)在更新data綁定屬性時(shí)候,更新頁(yè)面上輸入控件的值
    2022-09-09
  • vue3中關(guān)于路由hash與History的設(shè)置

    vue3中關(guān)于路由hash與History的設(shè)置

    這篇文章主要介紹了vue3中關(guān)于路由hash與History的設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vuex結(jié)合session存儲(chǔ)數(shù)據(jù)解決頁(yè)面刷新數(shù)據(jù)丟失問(wèn)題

    vuex結(jié)合session存儲(chǔ)數(shù)據(jù)解決頁(yè)面刷新數(shù)據(jù)丟失問(wèn)題

    在項(xiàng)目中表單篩選項(xiàng)里,選擇完之后刷新頁(yè)面數(shù)據(jù)就變了,沒有保留在自己選擇的選項(xiàng)上。本文使用session存儲(chǔ)數(shù)據(jù),具有一定的參考價(jià)值,感興趣的可以了解一下
    2021-09-09
  • 使用VueRouter的addRoutes方法實(shí)現(xiàn)動(dòng)態(tài)添加用戶的權(quán)限路由

    使用VueRouter的addRoutes方法實(shí)現(xiàn)動(dòng)態(tài)添加用戶的權(quán)限路由

    這篇文章主要介紹了使用VueRouter的addRoutes方法實(shí)現(xiàn)動(dòng)態(tài)添加用戶的權(quán)限路由,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-06-06
  • vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)之添加刪除功能

    vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)之添加刪除功能

    本文給大家?guī)?lái)一個(gè)小案例基于vue實(shí)現(xiàn)學(xué)生錄入系統(tǒng)功能,代碼簡(jiǎn)單易懂非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2018-07-07
  • Vue.js函數(shù)式組件的全面了解

    Vue.js函數(shù)式組件的全面了解

    函數(shù)式組件就是函數(shù)是組件,組件是函數(shù),它的特征是沒有內(nèi)部狀態(tài)、沒有生命周期鉤子函數(shù)、沒有this(不需要實(shí)例化的組件),這篇文章主要給大家介紹了關(guān)于Vue.js函數(shù)式組件的相關(guān)資料,需要的朋友可以參考下
    2021-10-10
  • Console高級(jí)用法總結(jié)

    Console高級(jí)用法總結(jié)

    Console 對(duì)象提供了瀏覽器控制臺(tái)調(diào)試的接口。在不同宿主環(huán)境上它的工作方式可能不一樣,但通常都會(huì)提供一套共性的功能,本文主要總結(jié)了Console的一些高級(jí)用法,感興趣的小伙伴可以參考一下
    2023-04-04
  • 解決Vue Loading PostCSS Plugin failed:Cannot find module autoprefixer問(wèn)題

    解決Vue Loading PostCSS Plugin failed:Cann

    這篇文章主要介紹了解決Vue Loading PostCSS Plugin failed:Cannot find module autoprefixer問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-03-03

最新評(píng)論