1、效果

2、 参数
| title | 标题 |
|---|---|
| text | 正文 |
| confirmTxt | 确定文案 |
| cancelTxt | 取消文案 |
事件
| onConfirm | 点击确定执行的回调函数 |
|---|---|
| onCancel | 点击取消执行的回调函数 |
3、使用
main.js 注册
import { Toast, Confirm } from '/Confirm';Vue.use(Confirm);
page
this.$confirm({text: '是否确认,授权天猫精灵,提供“您的联系方式”给红外码库厂商以便与您联系?',cancelTxt: '取消',confirmTxt: '确认',onConfirm: function() {},onCancel: function() {that.isChoose = false}})
4、插件代码
Confirm/index.ts
import ConfirmVue from './src/confirm.vue'let instancelet Confirm = {install(Vue) {Vue.prototype.$confirm = function (opts) {let defaultOpts = {title: '',text: '',confirmTxt: '确定',cancelTxt: '取消'}if (!instance) {instance = new ConfirmVue({el: document.createElement('div')})}// let options = Object.assign(defaultOpts, opts)// Object.assign(instance, options)for(var key in opts){if(opts.hasOwnProperty(key) === true){defaultOpts[key]=opts[key];}}var options = defaultOptsfor(var key in options){if(options.hasOwnProperty(key) === true){instance[key]=options[key];}}document.body.appendChild(instance.$el)Vue.nextTick(() => {instance.show = true})}}}export default Confirm
Confirm/src/confirm.vue
<template><div class="tn-confirm" v-show="show" @touchmove.stop.prevent><div class="tn-confirm__mask"></div><div class="tn-confirm__wrapper" @touchmove.stop.prevent><div class="tn-confirm__title">{{title}}</div><div class="tn-confirm__text">{{text}}</div><div class="tn-confirm__button"><div class="tn-confirm__button-cancel" @click="onCancelClick">{{cancelTxt}}</div><div class="tn-confirm__button-confirm" @click="onConfirmClick">{{confirmTxt}}</div></div></div></div></template><script lang="ts">import Vue, { PropOptions } from 'vue'export default Vue.extend({name: 'TnConfirm',componentName: 'TnConfirm',data() {return {show: false}},props: {text: String,title: String,confirmTxt: String,cancelTxt: String,onConfirm: {type: Function} as PropOptions<any>,onCancel: {type: Function} as PropOptions<any>},methods: {onCancelClick() {this.show = falsethis.onCancel && this.onCancel()},onConfirmClick() {this.show = falsethis.onConfirm && this.onConfirm()}}})</script><style lang="stylus">@import '../../../style/confirm.styl'</style>
confirm.styl
.tn-confirm&__wrappertop 50%left 50%position fixeddisplay flexflex-direction columnalign-items centertransform translate(-50%, -50%)width 270pxborder-radius 12pxbackground #fcfcfcbox-sizing border-boxtext-align centerz-index 10000&__titlemax-width 213pxmargin-top 20pxcolor #333font-size 17pxline-height 24px&__textcolor #333margin-top 10pxfont-size 13pxmax-width 143pxline-height 18px&__buttondisplay flexflex-direction rowwidth 100%margin-top 20pxheight 45pxline-height 45pxcolor #007AFFfont-size 17pxborder-top 1px solid rgb(235, 235, 235)&-cancelflex 1&-confirmborder-left 1px solid rgb(235, 235, 235)flex 1&__maskbackground rgba(0, 0, 0, 0.4)position fixedmargin 0top 0right 0bottom 0left 0z-index 10000&__textfont-size 10pxmargin-top 5pxdisplay inline-block
