vue 公用组件开发 确认框confirm

摘要:
文件目录:github地址:https://github.com/xingkongwuyu/vue-spa-experience/tree/master/src/components最终效果:组件源代码分析:confirm:confirmframework/index.jsimportconfirmBoxfrom'./src/index';exportdefault{install(Vue){Vue.pr

文件目录:

vue 公用组件开发 确认框confirm第1张

github地址:https://github.com/xingkongwuyu/vue-spa-experience/tree/master/src/components

最终的效果:

vue 公用组件开发 确认框confirm第2张

 组件的源码解析:

confirm :  confirm的框架

./index.js

import confirmBox from './src/index';
export default {
    install(Vue) {
      Vue.prototype.$confirm = confirmBox;
    },
  };

使用transition来实现动画效果

<template>
<transition name="mei-modal-fade">
    <div v-show="show" class="mei-modal" tabindex="-1" role="dialog" aria-labelledby="bombConfirmLabel" aria-hidden="false">
        <div class="mei-modal-mask"></div>
        <div class="mei-modal-wrap">
            <div class="mei-modal-content">
                <i class="mei-icon-close" @click="onClosed">
                    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" t="1515657730389" class="icon" style="" 
                    viewBox="0 0 1024 1024" version="1.1" p-id="2915" width="40" height="40"><path d="M557.311759 513.248864l265.280473-263.904314c12.54369-12.480043 12.607338-32.704421 0.127295-45.248112-12.512727-12.576374-32.704421-12.607338-45.248112-0.127295L512.127295 467.904421 249.088241 204.063755c-12.447359-12.480043-32.704421-12.54369-45.248112-0.063647-12.512727 12.480043-12.54369 32.735385-0.063647 45.280796l262.975407 263.775299-265.151458 263.744335c-12.54369 12.480043-12.607338 32.704421-0.127295 45.248112 6.239161 6.271845 14.463432 9.440452 22.687703 9.440452 8.160624 0 16.319527-3.103239 22.560409-9.311437l265.216826-263.807983 265.440452 266.240344c6.239161 6.271845 14.432469 9.407768 22.65674 9.407768 8.191587 0 16.352211-3.135923 22.591372-9.34412 12.512727-12.480043 12.54369-32.704421 0.063647-45.248112L557.311759 513.248864z" p-id="2916"/></svg>
                </i>
                   <div class="mei-modal-header">
                    <p>{{title}}</p>
                </div>
                <div class="mei-modal-body">
                    <div class="mei-status-icon-box">
                    </div>
                   <p v-if="!dangerouslyUseHTMLString">{{ text }}</p>
                   <p v-else v-html="text"></p>
                </div>
                <div class="mei-modal-footer">
                    <button type="button" class="mei-btn mei-btn-primary" id="confirmButtons1" @click="button[0].ontap">{{button[0].text}}</button>
                    <button type="button" class="mei-btn mei-btn-text" id="confirmButtons1" @click="button[1].ontap">{{button[1].text}}</button>
                </div>
            </div>
        </div>
    </div>
</transition>
</template>

<script>
    export default {
        data() {
            return {
                show: true,
                title: '1212',
                text: '12121111112',
                button: [],
                dangerouslyUseHTMLString:false
            }
        },
         methods:{
                onClosed(){
                    this.close();
                }
        }

    }
</script>

<style lang="scss" rel="stylesheet">
  @import "./../../../css/component.scss";
  .mei-modal-fade-enter,.mei-modal-fade-leave-to{
       transform: scale(0);
  }
  .mei-modal-fade-enter-active{
       animation: bounce-in 2s;
  }
   .mei-modal-fade-leave-active{
       animation: bounce-in 2s reverse;
  }
@keyframes bounce-in {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
</style>

 ./src/index.jsimport Vue from 'vue';

import confirmVue from './confirm.vue';
//参数配置 const defaults
= { show:false, title:'', text:'', button:[] }; let confirmVueLoading; const confirmVueConstructor = Vue.extend(confirmVue);
//这里关闭的时候返回promise confirmVueConstructor.prototype.close
= function() { var vm=this; confirmVueLoading=null; var promise=new Promise(function(resolve,reject){ if (vm.$el && vm.$el.parentNode) { vm.$el.parentNode.removeChild(vm.$el); } resolve(); vm.$destroy(); vm.show = false; }) return promise }; const confirmBox = (options = {}) => { if (Vue.prototype.$isServer) return; console.log(options); options = Object.assign({}, defaults, options);
let parent
= document.body ;
//没有关闭不允许新开
if(confirmVueLoading){ return confirmVueLoading } let instance = new confirmVueConstructor({ el: document.createElement('div'), data: options }); parent.appendChild(instance.$el); Vue.nextTick(() => { instance.show = true; }); confirmVueLoading=instance return instance; }; export default confirmBox;

引入全局 使用:

import VueConfirm from './components/confirm'
Vue.use(VueConfirm)
methods:{
  confirm () {
          var content = ` <div class="title">11111</div>`
          var vm=this
         const confirm = this.$confirm({
          title:'23232',
          text:content,
          dangerouslyUseHTMLString:true,
          button:[{
                text: '确定',
                ontap: function () {
                    confirm.close().then(function(res){
                     console.log(111233233231)
                   });
                }},
                {
                text: '取消',
                ontap: function () {
                  
                   confirm.close().then(function(res){
                       console.log('close')
                   });
                }
            }]
    
        });
     },
}

配置项:title :标题

        text:内容,

      dangerouslyUseHTMLString:内容是否是html;
button:按钮
text:按钮名称
             ontap:点击后的函数
 

免责声明:文章转载自《vue 公用组件开发 确认框confirm》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇ogg进程解析浏览器随机生成密码并保存下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vue elementui rules根据条件判断下一个选项必填和非必填的校验

<el-form-item label="HyperLink" prop="target" :rules="formInfo.type === 1?formRule.target:[{ required: false}]"> <el-input v-model="formInfo.target" clearable siz...

vue项目搭建

1.安装淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 2.安装vue脚手架 cnpm install vue-cli -g 3.安装webpack (npm)cnpm install -g webpack npm install webpack-cli -g 4...

动态菜单/权限管理的实现效果(数据前提:须做好 菜单、按钮、角色、用户等相关功能)

菜单管理 1.通过点击左侧树形某一项,右侧表格中出现对应菜单数据 2.实现菜单的增删改查功能——增改功能有树形下拉列表功能 3.列表数据——可排序、可下载excel、可自定义列      按钮管理 1. 通过点击左侧树形某一项,右侧表格中出现对应按钮数据 2.实现了按钮的增删改查功能——增改功能有树形下拉列表功能 3.列表数据——可排序、可下载excel...

Vue实例的的data对象

介绍 Vue的实例的数据对象data 我们已经用了很多了,数据绑定离不开data里面的数据。也是Vue的核心属性。 它是Vue绑定数据到HTML标签的数据源泉,另外Vue框架会自动监视data里面的数据变化,自动更新数据到HTML标签上去。本质原理是:Vue会自动将data里面的数据进行递归抓换成getter和setter,然后就可以自动更新HTML标签了...

vue自定义日期选择,类似美团日期选择,日历控件,vue日历区间选择

一个日历的控件,基于vue的,可以日历区间选择,可用于酒店日历区间筛选,动手能力强,可以修改成小程序版本的,先上效果图 里面的颜色样式都是可以修改的 选择范围效果 话不多说,直接上干货,代码可以直接复制访问 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4...

利用Bootstrap框架制作查询页面的界面

UI设计实战篇——利用Bootstrap框架制作查询页面的界面  Bootstrap框架是一个前端UI设计的框架,它提供了统一的UI界面,简化了设计界面UI的过程(缺点是定制了界面,调整的余地不是太大)。尤其是现在的响应时布局(我的理解是页面根据不同的分辨率,采用不同的页面元素的布局),在Bootstrap中很好的支持了,只要简单设置了属性,就能自动实现...