vue封装全局确认弹窗
下载文件1、弹窗组件
<template>
<view class="bombFrame" v-if="bshow" :class="show?'show':'hide'">
<view class="telate" :class="show?'bshow':'bhide'">
<view class="hint">
<view>{{title}}</view>
<view @touchstart.prevent="noClick">
<image src="./static/cha.svg" mode="" />
</view>
</view>
<view class="promptContent">
<view>
<image src="./static/gantan.svg" mode="" />
</view>
<view>{{content}}</view>
</view>
<view class="operate">
<view @touchstart.prevent="noClick">{{noBtnText}}</view>
<view @touchstart.prevent="yesClick">{{yesBtnText}}</view>
</view>
</view>
</view>
</template>
<script>
/**
*
*
* this.$Message({ content: "模式未保存,确定离开?" })
.then(() => {
console.log("yes");
})
.catch(() => {
console.log("cancel");
});
*
*
*/
export default {
props: {
title: {
type: String,
default: "提示",
},
yesBtnText: {
type: String,
default: "确定",
},
noBtnText: {
type: String,
default: "取消",
},
hasMark: {
type: Boolean,
default: true,
},
content: {
type: String,
default: "此操作将永久删除该文件, 是否继续?",
},
},
data() {
return {
promiseStatus: null,
show: false,
bshow: false,
};
},
methods: {
messag() {
let _this = this;
this.show = true;
this.bshow = true;
return new Promise(function (resolve, reject) {
_this.promiseStatus = { resolve, reject };
});
},
noClick() {
this.show = false;
setTimeout(() => {
this.bshow = false;
}, 500);
this.promiseStatus && this.promiseStatus.reject();
},
yesClick() {
this.show = false;
setTimeout(() => {
this.bshow = false;
}, 500);
this.promiseStatus && this.promiseStatus.resolve();
},
alertClick() {
this.show = false;
setTimeout(() => {
this.bshow = false;
}, 500);
this.promiseStatus && this.promiseStatus.resolve();
},
},
};
</script>
<style lang='scss'>
@keyframes move {
0% {
background: rgba(0, 0, 0, 0.5);
opacity: 1;
}
50% {
background: rgba(0, 0, 0, 0.2);
}
100% {
background: rgba(0, 0, 0, 0);
opacity: 0;
}
}
@keyframes move2 {
0% {
background: rgba(0, 0, 0, 0);
opacity: 0;
}
50% {
background: rgba(0, 0, 0, 0.2);
}
100% {
background: rgba(0, 0, 0, 0.5);
opacity: 1;
}
}
@keyframes move4 {
0% {
background: rgba(255, 255, 255, 1);
transform: translateY(0);
}
50% {
background: rgba(255, 255, 255, 0.5);
}
100% {
background: rgba(255, 255, 255, 0);
transform: translateY(-50rpx);
display: none !important;
}
}
@keyframes move3 {
0% {
background: rgba(255, 255, 255, 1);
transform: translateY(-50rpx);
}
100% {
background: rgba(255, 255, 255, 1);
transform: translateY(0);
}
}
.show {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
animation: move2 0.5s; /*自定义动画名称*/
animation-fill-mode: forwards; /*动画执行完后的状态*/
}
.hide {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
animation: move 0.5s; /*自定义动画名称*/
animation-fill-mode: forwards; /*动画执行完后的状态*/
}
.bshow {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
animation: move3 0.5s; /*自定义动画名称*/
animation-fill-mode: forwards;
}
.bhide {
-webkit-transition: -webkit-transform 1s;
transition: transform 1s;
animation: move1 0.5s; /*自定义动画名称*/
animation-fill-mode: forwards; /*动画执行完后的状态*/
}
.bombFrame {
position: fixed;
z-index: 9900;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0px 2px 9px 3px rgba(0, 0, 0, 0.5);
.telate {
background-color: #fff;
border-radius: 20rpx;
width: 700rpx;
padding: 30rpx;
box-sizing: border-box;
.hint {
display: flex;
align-items: center;
justify-content: space-between;
> view:nth-child(1) {
color: #303133;
font-size: 32rpx;
}
> view:nth-child(2) {
width: 50rpx;
height: 50rpx;
image {
width: 100%;
height: 100%;
}
}
}
.promptContent {
display: flex;
align-items: center;
margin-top: 30rpx;
> view:nth-child(1) {
width: 50rpx;
height: 50rpx;
image {
width: 100%;
height: 100%;
}
}
> view:nth-child(2) {
color: #606266;
font-size: 28rpx;
margin-left: 25rpx;
}
}
.operate {
display: flex;
justify-content: end;
margin-top: 30rpx;
> view:nth-child(1) {
padding: 15rpx 30rpx;
font-size: 24rpx;
border-radius: 6rpx;
background: #fff;
border: 1px solid #dcdfe6;
color: #606266;
}
> view:nth-child(2) {
padding: 15rpx 30rpx;
font-size: 24rpx;
margin-left: 20rpx;
border-radius: 6rpx;
background: #009788;
border: 1px solid #dcdfe6;
color: #ffffff;
}
}
}
}
</style>
2、往vue中挂载组件 (创建js)
import Vue from 'vue'
import messag from './index.vue'
const VueComponent = Vue.extend(messag);
const vm = new VueComponent().$mount();
let init = false;
let defaultOptions = {
yesBtnText: '确定',
noBtnText: '取消'
};
const message = function (options) {
Object.assign(vm, defaultOptions, options, {
type: 'confirm'
});
if (!init) {
document.body.appendChild(vm.$el);
init = true;
}
return vm.messag();
};
export default message;
3、应用全局组件
3.1 在main.js中引入全局
import Message from '@/components/message/index'
Vue.prototype.$Message = Message;
this.$Message({ content: "模式未保存,确定离开?" })
.then(() => {
console.log("yes");
}).catch(() => {
console.log("cancel");
});
vue封装全局确认弹窗的更多相关文章
- echars vue 封装全局组件 曲线 柱状图 同v-chars绿色系 配置样式
Echars vue封装 ,曲线图 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 用vue2.x注册一个全局的弹窗alert组件
一.在实际的开发当中,弹窗是少不了的,默认系统的弹窗样式太丑,难以满足项目的实际需求,所以需要自己定义弹窗组件,把弹窗组价定义为全局的,这样减少每次使用的时候引入麻烦,节省开发时间.本文将分享如何定义 ...
- main.js中封装全局登录函数
1. 在 main.js 中封装全局登录函数 通过 vue 对象的原型扩展,可以扩展一个函数,这样这个函数就可以在每一个界面通过类似指向对象的方式,去访问这个函数. 如下是 main.js 扩展的函数 ...
- Vue列表组件与弹窗组件示例
列表组件 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <me ...
- 用vue2.x注册一个全局的弹窗alert组件、confirm组件
一.在实际的开发当中,弹窗是少不了的,默认系统的弹窗样式太丑,难以满足项目的实际需求,所以需要自己定义弹窗组件,把弹窗组价定义为全局的,这样减少每次使用的时候引入麻烦,节省开发时间.本文将分享如何定义 ...
- [转]Vue项目全局配置微信分享思路详解
这篇文章给大家介绍了vue项目全局配置微信分享思路讲解,使用vue作为框架,使用vux作为ui组件库,具体内容详情大家跟随脚本之家小编一起学习吧 这个项目为移动端项目,主要用于接入公众号服务.项目采用 ...
- 浅析vue封装自定义插件
在使用vue的过程中,经常会用到Vue.use,但是大部分对它一知半解,不了解在调用的时候具体做了什么,因此,本文简要概述下在vue中,如何封装自定义插件. 在开始之前,先补充一句,其实利用vue封装 ...
- Vue 封装axios(四种请求)及相关介绍(十三)
Vue 封装axios(四种请求)及相关介绍 首先axios是基于promise的http库 promise是什么? 1.主要用于异步计算 2.可以将异步操作队列化,按照期望的顺序执行,返回符合预期的 ...
- 11 vue 自定义全局方法
//global.js// 定义vue 全局方 // 定义vue 全局方法 建议自定义的全局方法加_ 以示区分 export default { install(Vue, options = ...
- vue封装公用弹出框方法,实现点击出现操作弹出框
vue封装公用弹出框方法,实现点击出现操作弹出框 如上图所示,这次要实现一个点击出现操作弹框的效果:并将这个功能封装成一个函数,便于在项目的多个地方使用. 具体思路是: 封装一个组件,组件保护一个插槽 ...
随机推荐
- obj转换为gltf方法three.js一步一步来--性能优化超厉害的!!!!!超赞操作!!!Obj模型转Gltf模型并超强压缩!!!!!
1.准备好模型文件table.obj和table.mtl 2.下载obj2gltf 下载地址https://github.com/AnalyticalGraphicsInc/obj2gltf 解压至文 ...
- DVWA系列3:CSRF
DVWA系列3:CSRF 前言 CSRF(Cross-site request forgery),即跨站请求伪造,是一种挟制用户在当前已登录的Web应用程序上执行非本意的操作的攻击方法. 比如说,用户 ...
- Unity之UGUI鼠标进入离开&&拖拽实现
Unity之UGUI鼠标进入离开&&拖拽实现 前言: __小黑最近在写项目的时候就有个疑惑,UGUI中的Button组件,他的点击事件是怎么实现的!?我们自己能不能写一个!?之后在项目 ...
- Spring AOP与AspectJ的对比及应用
1 简介 AOP,即面向切面编程是很常用的技术,特别是在Java Web开发中.而最流行的AOP框架分别是Spring AOP和AspectJ. 2 Spring AOP vs AspectJ Spr ...
- LeetCode_单周赛_328
6291. 数组元素和与数字和的绝对差 代码 模拟即可 class Solution { public int differenceOfSum(int[] nums) { int ans = 0; i ...
- JavaScript的this指向详解
一.概念: 函数的上下文(this)由调用函数的方式决定,function是"运行时上下文"策略: 函数如果不调用,则不能确定函数的上下文. 二.规则: 对象打点调用它的方法函数, ...
- react中redux怎么使用
一.redux是什么? redux 就是react 全局状态管理,作用是存放全局数据 二.核心 state:存放数据 reducer:修改仓库数据 是一个函数,参数一:仓库中的数据,参数2:行为 ac ...
- C# HttpClient使用和注意事项,.NET Framework连接池并发限制
System.Net.Http.HttpClient 类用于发送 HTTP 请求以及从 URI 所标识的资源接收 HTTP 响应. HttpClient 实例是应用于该实例执行的所有请求的设置集合,每 ...
- xampp修改mysql数据库密码(测试成功)
转载: http://www.360doc.com/content/17/0608/14/8797027_661063783.shtml ------------------------------- ...
- word、excel、pdf等多种格式在线预览
第一种方式: 具体功能说明: http://view.xdocin.com/index.html 调用案例: <a href="http://www.xdocin.com/xdoc?_ ...