Coder Social home page Coder Social logo

pearofducks / create-v-model Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 147 KB

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

License: MIT License

HTML 2.89% Vue 10.25% CSS 1.84% JavaScript 85.02%
vue-3 v-model composition-api

create-v-model's Introduction

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 })
})

create-v-model's People

Contributors

pearofducks avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

create-v-model's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.