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

vue彈出框組件封裝實例代碼

 更新時間:2019年10月31日 13:55:04   作者:weixin_37035452  
這篇文章主要介紹了vue彈出框組件封裝,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下

新學vue,參考別人封裝彈出層組件。好用!

1.你需要先建一個彈出框的模板:

//首先創(chuàng)建一個mack.vue
<template>
 <div class="mack" v-if="isShow">
  <div class="mackWeb" :style="text.mackStyle">
   <div class="title font_b" v-if="text.title" :style="text.titleStyle">{{text.title.trim()}}</div>
   <div class="mesg font_s" v-if="text.mesg" :style="text.mesgStyle">{{text.mesg.trim()}}</div>
   <div v-html="text.cntMsg"></div>
   <div class="footb font_s">
    <div
     class="foot_l borderlf borderTop"
     @click="cancel"
     v-if="text.cancel"
     :style="text.cancelValStyle"
    >{{text.btn.cancelVal}}</div>
    <div
     class="foot_r borderTop"
     @click="confirm"
     v-if="text.confirm"
     :style="text.confirmValStyle"
    >{{text.btn.confirmVal}}</div>
   </div>
  </div>
 </div>
</template>

//寫js
<script>
 export default {
  data() {
   return {
    isShow: true,
    text: {
     title: "",
     mesg: "",
     cnTmesg: "",
     cancel: true,
     confirm: true,
     mackStyle: null,
  titleStyle: null,
  mesgStyle:null,
     cancelValStyle: null,
     confirmValStyle: null,
     btn: {
      confirmVal: "確定",
      cancelVal: "取消"
     }
    }
   };
  },
  methods: {
   cancel() {
    this.isShow = false;
   },
   confirm() {
    this.isShow = false;
   }
  }
};
</script>

//css
<style scoped lang='less'>
 .mack {
 position: fixed;
 width: 100%;
 height: 100%;
 overflow: hidden;
 top: 0;
 left: 0;
 background: rgba(21, 21, 21, 0.7);
 .font_b {
  font-size: 14/50rem;
  color: #231a2f;
 }
 .font_s {
  font-size: 12/50rem;
  color: #655a72;
 }
 .borderTop {
  border-top: 1/50rem solid #e4e4e4;
 }
 .mackWeb {
  background: #ffffff;
  width: 300/50rem;
  min-width: 300/50rem;
  margin: auto;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  .title {
   text-align: center;
   padding: 15/50rem 15/50rem 0 15/50rem;
  }
  .mesg {
   padding: 15/50rem;
   text-align: center;
  }
  .footb {
   display: inline-table;
   width: 100%;
   .borderlf {
    border-right: 1/50rem solid #e4e4e4;
   }
   div {
    display: table-cell;
    box-sizing: border-box;
    text-align: center;
    padding: 10/50rem 0;
   }
  }
 }
}
</style>

2.接著你需要一個js:mackjs.js

import Vue from 'vue';
import confirm from './mack';
let confirmConstructor = Vue.extend(confirm);
let theConfirm = function (text) {
  return new Promise((res, rej) => { //promise封裝,ok執(zhí)行resolve,no執(zhí)行rejectlet
   let confirmDom = new confirmConstructor({  
    el: document.createElement('div')
   })
   document.body.appendChild(confirmDom.$el); //new一個對象,然后插入body里面
   confirmDom.text = Object.assing( confirmDom.text,text);  //為了使confirm的擴展性更強,這個采用對象的方式傳入,所有的字段都可以根據(jù)需求自定義
   confirmDom.ok = function () {
    res()
    confirmDom.isShow = false
   }
   confirmDom.close = function () {
    rej()
    confirmDom.isShow = false
   }
  })
 }
 export default theConfirm; 
  //暴露出去,別忘記掛載到vue的原型上 
  //  => 在main.js里面先引入 import theConfirm from './components/confirm/confirm.js'
  //  => 再掛載 Vue.prototype.$confirm = theConfirm;
  //在需要的地方直接用以下方法調(diào)用即可:
  //  this.$confirm({
  //   type:'提示',
  //   msg:'是否刪除這條信息?',
  //   btn:{
  //     ok:'yes',
  //     no:'no'
  //   }
  // }).then(() => {
  //   console.log('ok')
  // })
  // .catch(() => {
  //   console.log('no')
  // })

-3.你接著需要在main.js導入這個文件

import macksjs from './assets/mackjs'
Vue.prototype.$confirm= macksjs ;

-4.最后在你需要引入的vue文件中直接調(diào)用就好了

<button @click="deleteaas">我是彈出框</button>
 methods:{
  deleteaas() {
   this.$confirm({
    title: "addd",
    mesg: "您確定不再關(guān)注該客戶嗎?",
    cntMsg: '<div class="helAA">你好</div>',
    cancelValStyle:{color:'red'},
    btn: {
     confirmVal: "確a定",
     cancelVal: "取a消"
    }
   })
    .then(() => {
     console.log("yes");
     //點擊確定之后的處理
    })
    .catch(() => {
     console.log("no");
    });
  }
 }

導入

總結(jié)

以上所述是小編給大家介紹的vue彈出框組件封裝實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

相關(guān)文章

  • Mock.js在Vue項目中的使用小結(jié)

    Mock.js在Vue項目中的使用小結(jié)

    這篇文章主要介紹了Mock.js在Vue項目中的使用,在vue.config.js中配置devServer,在before屬性中引入接口路由函數(shù),詳細步驟跟隨小編通過本文學習吧
    2022-07-07
  • 淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題

    淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題

    今天小編就為大家分享一篇淺談ElementUI中switch回調(diào)函數(shù)change的參數(shù)問題,具有很好的價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 關(guān)于vue.extend的使用及說明

    關(guān)于vue.extend的使用及說明

    這篇文章主要介紹了關(guān)于vue.extend的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • vue webpack多頁面構(gòu)建的實例代碼

    vue webpack多頁面構(gòu)建的實例代碼

    這篇文章主要介紹了vue webpack多頁面構(gòu)建的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下
    2018-09-09
  • 關(guān)于Vue Router中路由守衛(wèi)的應(yīng)用及在全局導航守衛(wèi)中檢查元字段的方法

    關(guān)于Vue Router中路由守衛(wèi)的應(yīng)用及在全局導航守衛(wèi)中檢查元字段的方法

    這篇文章主要介紹了關(guān)于Vue Router中路由守衛(wèi)的應(yīng)用及在全局導航守衛(wèi)中檢查元字段的方法,實現(xiàn)方法有兩種,本文通過實例代碼對每種方法介紹的很詳細,需要的朋友參考下
    2018-12-12
  • Vue腳手架配置代理服務(wù)器的兩種方式(小結(jié))

    Vue腳手架配置代理服務(wù)器的兩種方式(小結(jié))

    本文主要介紹了Vue腳手架配置代理服務(wù)器的兩種方式(小結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01
  • Vue打包優(yōu)化之生產(chǎn)環(huán)境刪除console日志配置

    Vue打包優(yōu)化之生產(chǎn)環(huán)境刪除console日志配置

    這篇文章主要為大家介紹了Vue打包優(yōu)化之生產(chǎn)環(huán)境刪除console日志配置詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • 詳解vue修改elementUI的分頁組件視圖沒更新問題

    詳解vue修改elementUI的分頁組件視圖沒更新問題

    這篇文章主要介紹了詳解vue修改elementUI的分頁組件視圖沒更新問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • el-form-renderer使用教程

    el-form-renderer使用教程

    本文主要介紹了el-form-renderer使用教程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-05-05
  • Vue3.0手寫輪播圖效果

    Vue3.0手寫輪播圖效果

    這篇文章主要為大家詳細介紹了Vue3.0手寫輪播圖效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10

最新評論