Last active
January 15, 2021 12:54
-
-
Save cannap/5b0898b5f8a018189e28277667caf216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div v-if="getPath()"> | |
<slot></slot> | |
</div> | |
</template> | |
<script> | |
import { get, isObject } from 'lodash-es'; | |
export default { | |
name: 'GetOrNothing', | |
props: { | |
target: { | |
type: Object, | |
required: true, | |
}, | |
path: { | |
type: String, | |
required: true, | |
}, | |
arrayCallBack: { | |
type: Function, | |
default: () => undefined, | |
}, | |
}, | |
methods: { | |
getPath() { | |
if (!isObject(this.target)) return false; | |
const result = get(this.target, this.path, undefined); | |
if (!result && process.env.NODE_ENV === 'development') { | |
throw new Error( | |
`Nothing found in: ${this.target} with Path: ${this.path}`, | |
); | |
} else { | |
// Todo: some sentry related stuff | |
} | |
}, | |
}, | |
}; | |
</script> | |
<style lang="scss" scoped></style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment