V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
Terry05
V2EX  ›  分享创造

v-dialogs v1.9.0 - 基于 Vue2 的简洁易用的弹出窗口,包含 modal, alert, mask, toast 等功能模式

  •  
  •   Terry05 ·
    TerryZ · 2018-04-28 10:08:54 +08:00 · 2076 次点击
    这是一个创建于 2402 天前的主题,其中的信息可能已经有所发展或是发生改变。

    v-dialogs

    基于Vue2.x的简洁易用的弹出窗口插件,其包含有 Modal, Alert, MaskToast 等功能模式



    更多文档、Demo

    请访问:

    the jQuery version: bDialog



    状态

    npm version license npm

    Install

    # install dependencies
    npm i v-dialogs --save
    

    Include plugin in your main.js file.

    import Vue from 'vue'
    import vDialog from 'v-dialogs';
    ...
    
    Vue.use(vDialog);
    



    Example / Use case

    Modal

    v-dialogs-modal

    import myComponent from './myComponent';//import component you want to open in Modal dialog
    
    new Vue({
      el: '#app',
      methods: {
        click(){
          //open component in Modal, and passing params to component
          this.$vDialog.modal(myComponent, {
            params: {
              a: 1,
              b: 2
            }
          });
        }
      }
    });
    

    receive params in component

    export default {
      name: 'myComponent',
      props: ['params']
      data(){
        console.log(this.params);//{a:1, b:2}
        return {};
      }
    }
    

    close dialog and return data in component

    export default {
      name: 'myComponent',
      props: ['params']
      data(){
        console.log(this.params);//{a:1, b:2}
        return {};
      },
      methods: {
        closeDialog(){
          let data = {
            a: 2,
            b: 4
          };
          //close current Modal dialog and return data to caller
          this.$vDialog.close(data);
        }
      }
    }
    

    Alert

    v-dialogs-alert

    //call a message alert dialog
    this.$vDialog.alert('This is a <b>Vue</b> dialog plugin: vDialog!');
    

    Mask

    v-dialogs-mask

    //open a full screen mask
    this.$vDialog.mask();
    

    有时候,你可以这样使用遮罩层:

    let that = this;
    let dialogKey = this.$vDialog.mask();
    // do some http request
    axios.post(...).then(resp){
      // do your business
      that.$vDialog.close(null, dialogKey);
    };
    

    Toast

    v-dialogs-toast

    open a Toast dialog in a corner

    //open a Toast dialog with message, default show to right bottom position
    this.$vDialog.toast('This is a Vue <b>vDialog</b> Toast!');
    
    //open a Toast with some options
    this.$vDialog.toast('This is a Vue <b>vDialog</b> Toast!',null, {
      messageType: 'warning',//theme set
      position: 'topLeft',// show position
      dialogCloseButton: false, // show dialog without close button
      closeTime: 3 // auto close toast times(second)
    });
    
    1 条回复    2018-05-03 13:06:20 +08:00
    del1214
        1
    del1214  
       2018-05-03 13:06:20 +08:00
    awesome
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2666 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 06:02 · PVG 14:02 · LAX 22:02 · JFK 01:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.