1.2.2 • Published 6 years ago

@vuejs-pt/vue-alert v1.2.2

Weekly downloads
68
License
MIT
Repository
github
Last release
6 years ago

@vuejs-pt/vue-alert

CircleCI GitHub license Vue 2.x npm GitHub issues

Table of Contents

Demo

Demo

Requirements

Installation

# npm
$ npm install @vuejs-pt/vue-alert

# yarn
$ yarn add @vuejs-pt/vue-alert

API

Available methods inside a VueJS component

The same parameters apply to all the methods in $alert expect the method hide and clearDefault

ParameterTypeDefaultDescription
durationnumber5000The duration for which the alert will be shown
forceRenderbooleantrueForce render when alert contents are changed
messagestringemptyMessage to be shown
transitionstringfadeTransition fade when switching between alerts, can be user defined
typestringfadeType of transition

If any of the values is not present on the method call then the default values will be used.

Set default values

this.$alert.setDefault({
  duration,
  forceRender,
  message,
  transition,
  type
})

Clear default values

this.$alert.clearDefault()

Show an alert

this.$alert.show({
  duration,
  forceRender,
  message,
  transition,
  type
})

Show an alert type info

this.$alert.info({
  duration,
  forceRender,
  message,
  transition
})

Show an alert type success

this.$alert.success({
  duration,
  forceRender,
  message,
  transition
})

Show an alert type warning

this.$alert.warning({
  duration,
  forceRender,
  message,
  transition
})

Show an alert type danger

this.$alert.danger({
  duration,
  forceRender,
  message,
  transition
})

Hide alert

this.$alert.hide()

Usage

The component vue-alert must be included either in the component using the vue-alert or a parent of this component, for example if there's a vue-alert instance at the root of the app.

It is possible to access the vue-alert component using the $alert variable on the component instance as shown in the below example.

The default bootstrap style are applied to the alert but this can be overriden by applying a new style to the following classes:

  • alert
  • alert-info
  • alert-success
  • alert-warning
  • alert-danger

The following transitions are available:

  • fade with force render
  • smooth without force render

main.js

import Vue from 'vue'
import VueAlert from '@vuejs-pt/vue-alert'
import App from './App'

Vue.use(VueAlert)

new Vue({
  el: '#app',
  template: '<App/>',
  components: { App }
})

App.vue

<template>
    <div id="app">
        <vue-alert></vue-alert>
        <example></example>
    </div>
</template>

<script>
import Example from './Example'

export default {
  components: {
    Example
  },
  mounted () {
    this.$alert.success({ message: 'Component mounted!' })
  }
}
</script>

<style>
.vue-alert {
  margin-top: 10px;
}
</style>

Example.vue

<template>
  <div>
    <h1>Example component</h1>
    <button class="btn btn-default" @click="showAlert">Click to use vue-alert</button>
  </div>
</template>

<script>
export default {
  methods: {
    showAlert () {
      this.$alert.show({
        message: 'Clicked the button!'
      })
    }
  }
}
</script>

License

The MIT License

1.2.2

6 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.9

7 years ago

0.6.8

7 years ago

0.6.7

7 years ago

0.6.6

7 years ago

0.6.5

7 years ago

0.6.4

7 years ago

0.6.3

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.4

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago