Subscribe on changes!

It's recommended to export the vue/ rruntime -core/ -> PropOptions

avatar
Sep 28th 2020

What problem does this feature solve?

Wean 'props' from the main body

What does the proposed API look like?

import {defineComponent} from 'vue';

const componentProp: {[key: string]: PropOptions} = {};

export default defineComponent({
    props: componentProp,
    render() {
        return <div>vue 3.0</div>
    }
})

image

avatar
Sep 29th 2020

What does this solve?

avatar
Oct 9th 2020

This might be a way to share the props definition between components.

avatar
Oct 11th 2020

You'd use { [key: string]: Prop } or ComponentPropsOptions for that.

avatar
Oct 12th 2020

谢谢

avatar
Sep 2nd 2021

I know this is old and pretty closed, but trying to made something like a props factory function to generate reusable props between components, I found quite dificult to return the right type.

My function is pretty simple

export function getIconDefaultProps() {
  return {
    width: {
      type: [Number, String],
      default: '1em'
    },
    height: {
      type: [Number, String],
      default: '1em'
    },
    color: {
      type: String,
      default: 'currentColor'
    }
  }
}

But trying to return a { [key: string]: Prop } as @KaelWD says

export function getIconDefaultProps(): { [key: string]: Prop } { /* ... */ }

I got a Generic type 'Prop' requires between 1 and 2 type arguments. error message, and I'm not pretty sure if create a type to solve this is what i need.

Then trying to return a ComponentPropsOptions

export function getIconDefaultProps(): ComponentPropsOptions { /* ... */ }

i got that the component where i wanna use the function doesn't resolve well the props type

image image