You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

vue-mutable

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-mutable

Proxies your props into mutable local state.

1.1.1
latest
Source
npm
Version published
Weekly downloads
5
-68.75%
Maintainers
1
Weekly downloads
 
Created
Source

Vue Mutable

Proxy your props into mutable local state.

Install

npm i --save vue-mutable
# or
yarn add vue-mutable
// Installs a global mixin
import { VueMutable } from 'vue-mutable';
Vue.use(VueMutable);

// Or, use the mixin directly in your component
import { mutableProps } from 'vue-mutable';

export default {
  mixins: [mutableProps]
  ...
}

Why

If you need to modify a prop in a components local state, you need to do a few things:

  • Define a data property
  • Set the data property value to the prop value in a lifecycle hook
  • Set a watcher for the prop so that if the parent updates the value, the internal value is synced
{
  props: {
    options: {
      default: []
    }
  },
  data() {
    return {
      _options: []
    }
  },
  created() {
    this.$data._options = this.options;
  },
  watch: {
    options(new, old) {
      this.$data._options = new;
    }
  }
}

Vue Mutable simplifies the process for you. Flag any prop as mutable and it will be accessible internally as a data property.

{
  props: {
    options: {
      default: [],
+     mutable: true
    }
  },
}

This will allow you to use this.$data._options in your component.

Keywords

Vue

FAQs

Package last updated on 16 Feb 2020

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