当前位置: 首页 > news >正文

vue使用ElementUI

1.安装

npm i element-ui -S

 

2.引入

2.1完整引入

import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';Vue.use(ElementUI);

2.2按需引入

说明:为了输入时候有提示,建议安装vue-helper

npm install babel-plugin-component -D

 

2.2.1创建babel.config.js

module.exports = {presets: ["@vue/cli-plugin-babel/preset"],plugins: [["component",{libraryName: "element-ui",styleLibraryName: "theme-chalk",},],],
};

2.2.2 main.js

import Vue from 'vue';
import { Button, Select } from 'element-ui';
import App from './App.vue';Vue.component(Button.name, Button);
Vue.component(Select.name, Select);

3.案例

说明:弹出框的实现。

3.1main.js

// element-ui挂在原型上
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;

3.2vue

<a class="btn" @click="open">立即支付</a>

3.3script

    // 弹出框async open() {// 生成一个二维码(地址)let url = await QRCode.toDataURL(this.payInfo.codeUrl);this.$alert(`<img src=${url} />`, "请你微信支付", {// 	是否将 message 属性作为 HTML 片段处理,// 也就是展示标签的意思dangerouslyUseHTMLString: true,// 是否居中布局center: true,// 是否显示取消按钮showCancelButton: true,// MessageBox 是否显示右上角关闭按钮showClose: true,// 取消按钮的文本cancelButtonText: "支付遇见问题",// 确定按钮的文本内容confirmButtonText: "已支付成功",// 关闭弹出框的配置值brforeClose: (type, instance, done) => {// type区分取消||确定按钮// instance当前组件实例// done:关闭弹出框的方法if (type == "cancel") {alert("请联系管理员");// 清除定时器clearInterval(this.timer);this.timer = null;done();} else {// 判断是否真的支付了// if (this.code == 200) {clearInterval(this.timer);this.timer = null;done()// 有的时候定时器还没监听到,用户支付成功了发现没跳转 立马点了支付成功的情况。this.$router.push("/paysuccess");// }}},});// 支付成功||失败// 支付成功,路由跳转,如果支付失败,提示信息// 定时器没有,那么要开启一个定时器if (!this.timer) {this.time = setTimeout(async () => {// 发请求获取用户支付的状态let result = await this.$API.reqPayStatus(this.orderId);// 如果code等于200,那么表示支付已经成功了if (result.code == 200 || result.code == 205) {// 清楚定时器clearInterval(this.timer);this.timer = null;// 保存codethis.code = result.code;// 关闭弹出框this.$msgbox.close();// 跳转到下一页路由this.$router.push("/paysuccess");}}, 1000);}},

 3.4展示

 

 

 

 

http://www.lryc.cn/news/116874.html

相关文章:

  • Python做一个绘图系统3:从文本文件导入数据并绘图
  • flutter开发实战-获取Widget的大小及位置
  • 软件测试工程师面试如何描述自动化测试是怎么实现的?
  • Qt5兼容使用之前Qt4接口 intersect接口
  • 【云原生】Kubernetes节点亲和性分配 Pod
  • 【Essential C++课后练习】纯代码(更新中)
  • C#仿热血江湖GClass
  • [SQL智慧航行者] - 用户购买商品推荐
  • Idea配置Scala开发环境
  • LT8711UXD 是一款高性能双通道 Type-C/DP1.4 至 HDMI2.0 转换器
  • Android APK体积优化(瘦身)
  • python技术栈 之 单元测试中mock的使用
  • python 提取冒号和逗号内的字符串
  • CentOS安装Postgresql
  • 云原生可观测框架 OpenTelemetry 基础知识(架构/分布式追踪/指标/日志/采样/收集器)...
  • 多用户跨境电商商品库系统快速搭建(全开源)
  • DataGrip 配置 HiveServer2 远程连接访问
  • 异常的使用
  • 软件安全测试包含哪些内容和方法?安全测试报告的必要性
  • 【代码随想录-leetcode第四题 20.有效的括号】
  • 造个轮子-任务调度执行小框架-IOC容器实现
  • npm发包中一些操作备忘
  • 15_基于Flink将pulsar数据写入到ClickHouse
  • Pycharm如何打断点进行调试?
  • 微服务02-docker
  • CSS:盒子模型 与 多种横向布局方法
  • 用node.js搭建一个视频推流服务
  • 【SpringCloud】Feign远程调用
  • 集合Collection-List-ArrayList学习
  • mybatispuls代码生成器