0.0.5 • Published 6 years ago

vue-prevent-back v0.0.5

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

Vue Prevent Back

vue-js downloads npm-version

Prevent Back Directive for Vue2.

Demo

Installation

npm install vue-prevent-back --save

Usage

ES6

import Vue from 'vue'
import VuePreventBack from 'vue-prevent-back'

Vue.use(VuePreventBack, options)

Globals

<html>
<head>
  ...
</head>
<body>
  <div id="app">
    <form v-prevent-back>
        ...
    </form>
  </div>

  <script src="path/to/vue.js"></script>
  <script src="path/to/vue-prevent-back.js"></script>
  <script>
    new Vue({
      el: '#app'
    })
  </script>
</body>
</html>

Example

Install Options

OptionTypeDefaultDescription
nameString'prevent-back'change directive name.
messageString'You have unsaved work. Are you sure you want to leave this page?'change default message.

name Example.

import VuePreventBack from 'vue-prevent-back'

Vue.use(VuePreventBack, {
    name: "my-prevent-back",
})

Now, you can use directive below.

<form v-my-prevent-back></form>

message Example.

import VuePreventBack from 'vue-prevent-back'

Vue.use(VuePreventBack, {
    message: "Are you OKay?",
})

Value

KeyTypeDefaultDescription
messageStringinstall options's messagechange confirm message.
testerFunction() => truechecking that form is changing.

message Example.

<form v-prevent-back="'Are you Okay?'"></form>
<form v-prevent-back="{message: 'Are you Okay?'}"></form>

tester Example.

<form v-prevent-back="{tester: () => !isChange)}">
  <CustomInput @change="isChange = true" />
</form>
export default {
  data() {
    return {
      isChange: false,
    };
  },
};

Modifier

KeyDescription
vue-router-disablenot prevent, when vue router changes.
beforeunload-disablenot prevent, when beforeunload event occured.
tester-onlyusing tester only. vue-prevent-back check all input's changing. if turn on this modifier, only check tester method.

License

MIT

0.0.5

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago