Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

create-v-model

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-v-model

create v-model bindings quickly and easily - without having to remember which props to use

  • 2.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
76
decreased by-45.32%
Maintainers
1
Weekly downloads
 
Created
Source

create-v-model

create v-model bindings quickly and easily - without having to remember which props to use

install

yarn add create-v-model
npm install --save create-v-model

use

import { modelProps, createModel } from 'create-v-model'

export default {
  props: {
    ...modelProps()
  },
  setup: (props) => ({
    model: createModel(props)
  })
}

api

modelProps

Provides all three props used in binding a standard v-model to a component

props: {
  ...modelProps({
    modelName: string = 'modelValue',
    modelType: any = null,
    modelDefault: any,
    modifierDefault: any = (() => ({}))
  })
}
  • modelName: the name of the model; leave this as the default for plain v-model, and otherwise give it the NAME in v-model:NAME
  • modelType: an optional type to specify the model should be
  • modelDefault: an optional value to specify the intial value of the model (typically used for absent prop detection)
  • modifierDefault: an optional alternative default for the modelModifiers prop (or equivalent for named models)

createModel

Creates a new computed that can be used as a standard ref and will reflect changes on v-model

setup: (props, { emit }) => ({
  model: createModel({
    props,
    emit?, // see below for info about emit being optional
    modelName: string = 'modelValue',
    modifier?: function
  })
})
  • props: the props from setup - this is required
  • emit: if emit is provided, then Vue's built-in modifiers (trim and number) will be enabled - and events will be emitted for updates instead of directly calling the relevant onUpdate function directly
  • modelName: the name of the model; leave this as the default for plain v-model, and otherwise give it the NAME in v-model:NAME
  • modifier: a function of the form below, this will be called whenever the model would call set
    • (value: typeof modelType, modelModifiersObject: object) => typeof modelType

createModelFactory

Creates a higher-order function, can be useful for hooks and other utilities - otherwise effectively the same as createModel

setup: (props, { emit }) => ({
  model: createModelFactory({ modelName, modifier })({ props, emit })
})

FAQs

Package last updated on 30 Sep 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc