Created
January 10, 2020 13:26
-
-
Save abdumu/17eeca0bc3cb36fcc938ea73903c43c7 to your computer and use it in GitHub Desktop.
optional helper for vue
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
Vue.mixin({ methods: { | |
optional(variable) { | |
return new Proxy(typeof variable === undefined || variable === null ? {} : variable, { | |
get(target, prop) { return prop in target ? target[prop] : null; } | |
}); | |
}, | |
}}) | |
//usage: {{ optional(user).email }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
information about Proxy in javascript: https://javascript.info/proxy