Element Notification通知的实现示例


Posted in Javascript onJuly 27, 2020

组件— 通知

基本用法

Element Notification通知的实现示例

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open1">
  可自动关闭
 </el-button>
 <el-button
  plain
  @click="open2">
  不会自动关闭
  </el-button>
</template>

<script>
 export default {
  methods: {
   open1() {
    const h = this.$createElement;

    this.$notify({
     title: '标题名称',
     message: h('i', { style: 'color: teal'}, '这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案这是提示文案')
    });
   },

   open2() {
    this.$notify({
     title: '提示',
     message: '这是一条不会自动关闭的消息',
     duration: 0
    });
   }
  }
 }
</script>

带有倾向性

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open1">
  成功
 </el-button>
 <el-button
  plain
  @click="open2">
  警告
 </el-button>
 <el-button
  plain
  @click="open3">
  消息
 </el-button>
 <el-button
  plain
  @click="open4">
  错误
 </el-button>
</template>

<script>
 export default {
  methods: {
   open1() {
    this.$notify({
     title: '成功',
     message: '这是一条成功的提示消息',
     type: 'success'
    });
   },

   open2() {
    this.$notify({
     title: '警告',
     message: '这是一条警告的提示消息',
     type: 'warning'
    });
   },

   open3() {
    this.$notify.info({
     title: '消息',
     message: '这是一条消息的提示消息'
    });
   },

   open4() {
    this.$notify.error({
     title: '错误',
     message: '这是一条错误的提示消息'
    });
   }
  }
 }
</script>

自定义弹出位置

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open1">
  右上角
 </el-button>
 <el-button
  plain
  @click="open2">
  右下角
 </el-button>
 <el-button
  plain
  @click="open3">
  左下角
 </el-button>
 <el-button
  plain
  @click="open4">
  左上角
 </el-button>
</template>

<script>
 export default {
  methods: {
   open1() {
    this.$notify({
     title: '自定义位置',
     message: '右上角弹出的消息'
    });
   },

   open2() {
    this.$notify({
     title: '自定义位置',
     message: '右下角弹出的消息',
     position: 'bottom-right'
    });
   },

   open3() {
    this.$notify({
     title: '自定义位置',
     message: '左下角弹出的消息',
     position: 'bottom-left'
    });
   },

   open4() {
    this.$notify({
     title: '自定义位置',
     message: '左上角弹出的消息',
     position: 'top-left'
    });
   }
  }
 }
</script>

带有偏移

Element Notification通知的实现示例

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open">
  偏移的消息
 </el-button>
</template>

<script>
 export default {
  methods: {
   open() {
    this.$notify({
     title: '偏移',
     message: '这是一条带有偏移的提示消息',
     offset: 100
    });
   }
  }
 }
</script>

使用 HTML 片段

Element Notification通知的实现示例

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open">
  使用 HTML 片段
 </el-button>
</template>

<script>
 export default {
  methods: {
   open() {
    this.$notify({
     title: 'HTML 片段',
     dangerouslyUseHTMLString: true,
     message: '<strong>这是 <i>HTML</i> 片段</strong>'
    });
   }
  }
 }
</script>

隐藏关闭按钮

Element Notification通知的实现示例

Element Notification通知的实现示例

<template>
 <el-button
  plain
  @click="open">
  隐藏关闭按钮
 </el-button>
</template>

<script>
 export default {
  methods: {
   open() {
    this.$notify.success({
     title: 'Info',
     message: '这是一条没有关闭按钮的消息',
     showClose: false
    });
   }
  }
 }
</script>

全局方法

Element 为 Vue.prototype 添加了全局方法 $notify。因此在 vue instance 中可以采用本页面中的方式调用 Notification。

单独引用

Element Notification通知的实现示例

Options

Element Notification通知的实现示例
Element Notification通知的实现示例

方法

Element Notification通知的实现示例

Vue项目中Element的Notification通知若干问题

要求是后台推送过来一条消息,前端接收后再将消息进行提炼后通过弹窗通知用户。前后端发送接收消息用的技术是webIm,这个先不提了,官方文档配置一下就OK了。

遇到的问题是产品给的设计图与Element的出入很大,所以就使用了Element的dangerouslyUseHTMLString属性,即把需要发送的消息写成HTML结构发送

Element Notification通知的实现示例

在模板字符串中,加载图片那里发现路径无法实现图片的加载,试了很多种方法,发现使用require+${}的方法最好用,上图中<img src=${this.imgUrlNormal}>中,${}保存的地址需要先在data里边return出来

Element Notification通知的实现示例

这个问题就解决了。

第二个问题是遇到了样式的调整问题,Element的权重太高,真的是不太好搞,在网上找了很多解决方案,发现把<style>标签中的scoped去掉这种方法可以解决问题。

并且用到了costomClass这个属性,这个属性是给元素添加一个class类名,自己来添加样式。

这样,这个弹窗的问题就解决了。

到此这篇关于Element Notification通知的实现示例的文章就介绍到这了,更多相关Element Notification通知内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!

Javascript 相关文章推荐
javascript 事件绑定问题
Jan 01 Javascript
javascript变量声明实例分析
Apr 25 Javascript
javascript实现动态改变层大小的方法
May 14 Javascript
表单验证正则表达式实例代码详解
Nov 09 Javascript
Angular2表单自定义验证器的实现
Oct 19 Javascript
node.js 抓取代理ip实例代码
Apr 30 Javascript
利用Javascript获取选择文本所在的句子详解
Dec 03 Javascript
解决vue-cli + webpack 新建项目出错的问题
Mar 20 Javascript
express.js中间件说明详解
Mar 19 Javascript
Vue + Element UI图片上传控件使用详解
Aug 20 Javascript
深入了解Vue.js 混入(mixins)
Jul 23 Javascript
html中创建并调用vue组件的几种方法汇总
Nov 17 Javascript
Vue中watch、computed、updated三者的区别及用法
Jul 27 #Javascript
Element Backtop回到顶部的具体使用
Jul 27 #Javascript
解决vue中的无限循环问题
Jul 27 #Javascript
Element MessageBox弹框的具体使用
Jul 27 #Javascript
Vue 组件复用多次自定义参数操作
Jul 27 #Javascript
使用Element的InfiniteScroll 无限滚动组件报错的解决
Jul 27 #Javascript
Element InfiniteScroll无限滚动的具体使用方法
Jul 27 #Javascript
You might like
利用PHP生成静态html页面的原理
2016/09/30 PHP
详解PHP函数 strip_tags 处理字符串缺陷bug
2017/06/11 PHP
Mootools 1.2教程 滑动效果(Slide)
2009/09/15 Javascript
js 优化次数过多的循环 考虑到性能问题
2011/03/05 Javascript
brook javascript框架介绍
2011/10/10 Javascript
基于jquery实现后台左侧菜单点击上下滑动显示
2013/04/11 Javascript
js创建子窗口并且回传值示例代码
2013/07/02 Javascript
js用正则表达式来验证表单(比较齐全的资源)
2013/11/17 Javascript
JavaScript中实现单体模式分享
2015/01/29 Javascript
微信小程序 实现列表项滑动显示删除按钮的功能
2017/04/13 Javascript
如何理解Vue的作用域插槽的实现原理
2017/08/19 Javascript
vue awesome swiper异步加载数据出现的bug问题
2018/07/03 Javascript
JavaScript枚举选择jquery插件代码实例
2020/11/17 jQuery
js实现简易计算器小功能
2020/11/18 Javascript
在Python中处理列表之reverse()方法的使用教程
2015/05/21 Python
使用Python的Tornado框架实现一个Web端图书展示页面
2016/07/11 Python
python实现下载整个ftp目录的方法
2017/01/17 Python
Python3计算三角形的面积代码
2017/12/18 Python
python爬取各类文档方法归类汇总
2018/03/22 Python
Python爬取数据并写入MySQL数据库的实例
2018/06/21 Python
python利用thrift服务读取hbase数据的方法
2018/12/27 Python
Python CVXOPT模块安装及使用解析
2019/08/01 Python
通过实例学习Python Excel操作
2020/01/06 Python
Python爬取数据并实现可视化代码解析
2020/08/12 Python
如何将Pycharm中调整字体大小的方式设置为&quot;ctrl+鼠标滚轮上下滑&quot;
2020/11/17 Python
世界上最悠久的自行车制造商:Ribble Cycles
2017/03/18 全球购物
美国女性卫生用品公司:Thinx
2017/06/30 全球购物
新西兰领先的内衣店:Bendon Lingerie新西兰
2018/07/11 全球购物
迷你分体式空调:SoGoodToBuy
2018/08/07 全球购物
黄金酒广告词
2014/03/21 职场文书
大学生优秀班干部事迹材料
2014/05/26 职场文书
2014离婚协议书范文(3篇)
2014/11/29 职场文书
小学教师2014年度工作总结
2014/12/03 职场文书
政府会议通知范文
2015/04/15 职场文书
2016年小学“感恩教师”主题队日活动总结
2016/04/01 职场文书
源码安装apache脚本部署过程详解
2022/09/23 Servers