Skip to content

Instantly share code, notes, and snippets.

@cannap
Last active January 15, 2021 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannap/5b0898b5f8a018189e28277667caf216 to your computer and use it in GitHub Desktop.
Save cannap/5b0898b5f8a018189e28277667caf216 to your computer and use it in GitHub Desktop.
<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