GithubHelp home page GithubHelp logo

lynzz / vue-popup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elemefe/vue-popup

0.0 2.0 0.0 39 KB

A popup mixin for vue.js

License: MIT License

Makefile 0.65% JavaScript 81.84% Vue 12.80% HTML 1.72% CSS 3.00%

vue-popup's Introduction

Overview

vue-popup is a popup mixin for vue.js

Installation

First, install vue-popup from npm:

$ npm install vue-popup

Then import it:

import Popup from 'vue-popup';
require('vue-popup/lib/popup.css');

Usage

In a vue instance, define its mixins:

mixins: [Popup]

Then vue-popup's APIs(see below) are accessible via the vue instance's props attribute.

Example

Goal: on your page you have a button. When it's clicked, an alert pops up.

First let's deal with the alert component in alert.vue:

<template>
  <div v-if="rendered" v-show="visible" class="alert">
    <p>Alert!</p>
  </div>
</template>
<style>
  .alert {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
</style>
<script>
  import Popup from 'vue-popup';
  require('vue-popup/lib/popup.css');
  export default {
      mixins: [Popup],
      props: {
        modal: {
          default: true
        },
        closeOnClickModal: {
          default: true
        }
      }
    };
</script>

As you can see, v-if="rendered" and v-show="visible" should be added on the outermost tag of the component. Its props attribute has two keys: modal and closeOnClickModal, please refer to API below for detailed information.

That's it for the alert component. Let's move on to the main page:

<template>
  <button @click="alertVisible = true">Open Dialog</button>
  <alert :visible.sync="alertVisible"></alert>
</template>
<script>
  const Alert = require('./alert.vue');
  export default {
    components: { Alert },
    data() {
      return {
        alertVisible: false
      };
    }
  };
</script>

Note that the main page's alertVisible syncs with the component's visible, so when the button is clicked, alertVisible becomes true thus the alert component pops up.

API

Option Description Value Default
visible visibility of the popup element Boolean 'false'
openDelay time before the popup element opens Number, in millisecond
closeDelay time before the popup element closes Number, in millisecond
zIndex z-index of the popup element Number
modal determines if a modal pops with the popup element Boolean 'false'
modalClass class name of the modal String
closeOnPressEscape determines if the popup element closes when escape is clicked Boolean 'false'
closeOnClickModal determines if the popup element closes when the modal is clicked Boolean 'false'

vue-popup's People

Contributors

baiyaaaaa avatar leopoldthecoder avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.