富贵资源网 Design By www.hznty.com

最近要写个弹框,发现element-ui弹框样式还可以,就copy下来改吧改吧。也不分步骤详细介绍了直接上代码。

在组件目录中新建文件夹message

我把message目录里的东西给大家贴出来

vue项目中仿element-ui弹框效果的实例代码

message文件夹

vue项目中仿element-ui弹框效果的实例代码

src文件夹

index.js

import Message from './src/main.js';
export default Message;

mian.js

import Vue from 'vue';
import Main from './main.vue';
let MessageConstructor = Vue.extend(Main);
let instance;
let instances = [];
let seed = 1;
const Message = (options = {}) => {
 if (typeof options === 'string') {
 options = {
  message: options
 };
 }
 let userOnClose = options.onClose;
 let id = 'message_' + seed++;
 options.onClose = function() {
 Message.close(id, userOnClose);
 };
 instance = new MessageConstructor({
 data: options
 });
 instance.id = id;
 instance.vm = instance.$mount();
 document.body.appendChild(instance.vm.$el);
 instance.vm.visible = true;
 instance.dom = instance.vm.$el;
 instance.dom.style.zIndex = 999;
 instances.push(instance);
 return instance.vm;
}
['success', 'warning', 'info', 'error'].forEach(type => {
 Message[type] = options => {
 if (typeof options === 'string') {
  options = {
  message: options
  };
 }
 options.type = type;
 return Message(options);
 };
});
Message.close = function(id, userOnClose) {
 for (let i = 0, len = instances.length; i < len; i++) {
 if (id === instances[i].id) {
  if (typeof userOnClose === 'function') {
  userOnClose(instances[i]);
  }
  instances.splice(i, 1);
  break;
 }
 }
};
Message.closeAll = function() {
 for (let i = instances.length - 1; i >= 0; i--) {
 instances[i].close();
 }
};

export default Message;

mian.vue

<template>
 <transition name="message-fade">
  <div :class="[
   'message',
   type && !iconClass "
    v-show="visible"
    @mouseenter="clearTimer"
    @mouseleave="startTimer">
   <i :class="iconClass" v-if="iconClass"></i>
   <i :class="typeClass" v-else></i>
   <slot>
    <p v-if="!dangerouslyUseHTMLString" class="message-content">{{ message }}</p>
    <p v-else v-html="message" class="message-content"></p>
   </slot>
   <i v-if="showClose" class="message-close-btn icon-close" @click="close"></i>
  </div>
 </transition>
</template>
<script>
 const typeMap = {
 success: 'success',
 info: 'info',
 warning: 'warning',
 error: 'error'
 };
 export default {
 data () {
  return {
  visible: false,
  message: '',
  duration: 1000,
  type: 'info',
  iconClass: '',
  customClass: '',
  onClose: null,
  showClose: false,
  closed: false,
  timer: null,
  dangerouslyUseHTMLString: false,
  center: false
  }
 },
 computed: {
  typeClass() {
  return this.type && !this.iconClass
   "less">
 .message {
  min-width: 200px;
  box-sizing: border-box;
  border-radius: 3px;
  border: 1px solid #ebeef5;
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  background-color: #edf2f3;
  transition: opacity 0.3s, transform .4s;
  overflow: hidden;
  padding: 10px;
  display: flex;
  align-items: center;
 }
 .message-icon{
  width: 15px;
  height: 15px;
  border-radius: 100%;
  background: #fff;
  display: inline-block;
  margin-right: 10px;
  &.icon-success{
   background: url("../../../assets/image/icon-success.png") no-repeat center center;
   background-size: auto 100%;
  }
  &.icon-error{
   background: url("../../../assets/image/icon-error.png") no-repeat center center;
   background-size: auto 100%;
  }
  &.icon-info{
   background: url("../../../assets/image/icon-info.png") no-repeat center center;
   background-size: auto 100%;
  }
  &.icon-warning{
   background: url("../../../assets/image/icon-warning.png") no-repeat center center;
   background-size: auto 100%;
  }
 }
 .message-success{
  background: #f2f8ec;
  border-color: #e4f2da;
  .message-content{
   color: #7ebe50;
  }
 }
 .message-error{
  background: #fcf0f0;
  border-color: #f9e3e2;
  .message-content{
   color: #e57470;
  }
 }
 .message-warning{
  background: #fcf6ed;
  border-color: #f8ecda;
  .message-content{
   color: #dca450;
  }
 }
 .message-info{
  background: #eef2fb;
  border-color: #ebeef4;
  .message-content{
   color: #919398;
  }
 }
 .message-fade-enter,
 .message-fade-leave-active {
  opacity: 0;
  transform: translate(-50%, -100%);
 }
</style>

以上就是封装的所有代码
 接下来就来看看如何引用

main.js中引入

import Message from '@/components/message/index.js'

Vue.prototype.$message = Message

调用

在你需要的页面调用

this.$message({
  message: '提示消息',
  type:'error' //type有四个值 1.error 2.success 3.info 4.warning
});

vue项目中仿element-ui弹框效果的实例代码

type为success

vue项目中仿element-ui弹框效果的实例代码

type为warning

vue项目中仿element-ui弹框效果的实例代码

type为info

vue项目中仿element-ui弹框效果的实例代码

type为errpr

小icon的图片用自己的图片哦

总结

以上所述是小编给大家介绍的vue项目中仿element-ui弹框效果的实例代码,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。