Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-boundary

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-boundary

Catch javascript errors in a vue 2 component and render fallback components of easy way.

  • 1.1.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source
MIT npm version Vulnerabilities

Catch javascript errors in a vue 2 component and render fallback components of easy way.


Introduction

This plugin available an component to catches javascript errors in a vue 2 component and handles it by rendering a fallback component, isolating the error and handling it specifically, ensuring that the rest of the application is not affected by an isolated error in some UI component.

Error Boundaries is a concept introduces by React 16: Read more about


## 🚚 Install
 yarn add vue-boundary  // npm install --save vue-boundary

Global

import Vue from 'vue';
import VueBoundary from "vue-boundary";

Vue.use(VueBoundary);

Local

import VueBoundary from "vue-boundary";

export default {
  components: {
    VueBoundary
  },
};

📌 Usage

Fallback component

With slot #fallback
<template>
  <VueBoundary @error-captured="onError" >
      <SomeComponent />

      <template #fallback>
        <div>Oops, something went wrong!</div>
      </template>
  </VueBoundary>
</template>

<script>
export default {
    methods:{
        onError({ error, info, vm }){
            console.error(error.fileName, error.message, error.stack)
            console.error('Error info =>', info)
            console.error('Component instance =>', vm)
        }
    }
}
</script>
with prop fallback
<template>
  <VueBoundary :fallback="ErrorMessage">
      <SomeComponent />
  </VueBoundary>
</template>

<script>
import ErrorCard from './ErrorCard.vue'

export default {
    data: () => ({
        ErrorMessage: ErrorCard
    }),
}
</script>

Error catch

Whit prop onError
<template>
  <VueBoundary :onError="myCallbackHere" >
      ...
  </VueBoundary>
</template>

<script>

export default {
    ...
    methods:{
        myCallbackHere({ error, info, vm }){
            console.error(error, info, vm)
        }
    }
}
</script>
Or errorCaptured event
<template>
  <VueBoundary :fallback="componentFallback" :@errorCaptured="onErrorCaptured" >
      ...
  </VueBoundary>
</template>

<script>

export default {
    ...
    methods:{
        onErrorCaptured({ error, info, vm }){
            console.error(error, info, vm)
        }
    }
}
</script>

Props

NametypeDefaultdescription
onErrorFunctionundefinedCallback to listen when an error it's captured, receive an object with 3 property: error, info and vm
fallbackObjectnullComponent to render if the default slot catch an error.
propagationBooleanfalsePrevents further propagation of the current error for another "errorCaptured" parents hooks. https://vuejs.org/v2/api/#errorCaptured

Events

NameDescription
error-capturedReceive an object with 3 property: error, info and vm

Slots

NameDescription
defaultThe default slot
fallbackSlot to render if the default slot catch an error.

🔖 License

MIT

Keywords

FAQs

Package last updated on 20 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc