Skip to content

Vue 2.x plugin, which allows to pass an array of props containing both strings and objects

Notifications You must be signed in to change notification settings

p1pchenk0/vue-mixed-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

vue-mixed-props

npm npm

Let's say, application has a component, which already has some props defined as an array of strings and it is totally fine for developer or dev team to leave it as it is:

export default {
  name: 'SampleComponent',
  props: [ 'foo', 'bar', 'baz' ]
}

But then, one day, a new prop should be added with type and default value defined. Currently developer has to rewrite existing array of props into object just for adding 1 new prop with default value.

Current plugin allows using mixed array of strings and object for detailed props:

export default {
  name: 'SampleComponent',
  props: [
    'foo',
    'bar',
    'baz',
    {
      tar: {
        type: String,
        default: 'Hi'
      }
    }
  ]
}

Or you can use object for props with array of some string props:

  export default {
    name: 'SampleComponent',
    props: {
      $strings: ['foo', 'bar', 'baz'],
      tar: {
        type: String,
        default: 'Hi'
      }
    }
  }

Usage:

  import Vue from 'vue'
  import MixedProps from 'vue-mixed-props'

  Vue.use(MixedProps)

Plugin works also with SSR.

About

Vue 2.x plugin, which allows to pass an array of props containing both strings and objects

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published