Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

guastallaigor/v-safe

Repository files navigation

v-safe

Vue.js directive to show text values from deep objects without any errors

Version Github file size Downloads Vue2 Say Thanks!

Why

This is meant to avoid this type of error when you are using deep objects, that usually can happen when you're expecting a deep object after a Promise

<span>{{ a.b.c.d }}</span>

[Vue warn]: Error in render: "TypeError: Cannot read property 'c' of undefined"

How to install

npm

$ npm install v-safe --save

yarn

$ yarn add v-safe

Quick start

Vue.js

You can import in you main.js file

import Vue from 'vue'
import VSafe from 'v-safe'

Vue.use(VSafe)

Nuxt.js

You can import as a Nuxt.js plugin

~/plugins/v-safe.js

import Vue from 'vue'
import VSafe from 'v-safe'

Vue.use(VSafe)

and then import it in your nuxt.config.js file

plugins: [
  '~/plugins/v-safe.js'
]

Basic usage

<template>
  <span v-safe="'a.b.c.d'"></span>
</template>

<script>
export default {
  data:() => ({
    a: {
      b: {
        c: {
          d: 'safe'
        }
      }
    }
  })
}
</script>

Development

contributions welcome

Fork the project and enter this commands in your terminal

git clone https://github.com/YOUR_GITHUB_USERNAME/v-safe.git
cd v-safe
yarn

Buy Me A Coffee

License

MIT © guastallaigor

About

Vue.js directive to show text values from deep objects without any errors

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published