UNPKG

vue-prevent-unload

Version:

Vue component that conditionaly prevents page leave/reload

2 lines (1 loc) 463 B
var PreventUnload={name:"PreventUnload",abstract:!0,render:function(){return null},props:{when:Boolean,message:{type:String,default:"Changes you made may not be saved."}},methods:{handleUnload:function(e){if(this.when)return e.returnValue=this.message,this.message}},mounted:function(){window.addEventListener("beforeunload",this.handleUnload)},beforeDestroy:function(){window.removeEventListener("beforeunload",this.handleUnload)}};export default PreventUnload;