Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prop sanitization #8049

Closed
e2o opened this issue Apr 18, 2018 · 2 comments
Closed

Prop sanitization #8049

e2o opened this issue Apr 18, 2018 · 2 comments

Comments

@e2o
Copy link

e2o commented Apr 18, 2018

What problem does this feature solve?

It would be an extensions of the props API that would allow us to sanitize a given value for a property before passing it onto the component instance. Right now there is no real way of doing this before the value is being set on the component.

What does the proposed API look like?

This whould work very similarly to how validators for props work, by passing a sanitizer function in the prop definition.

Vue.component('my-component', {
  props: {
    title: {
      type: String,
      // Custom sanitization function
      sanitizer: function (value) {
        // The title must not have any leading or trailing whitespace
        return value.trim()
      }
    }
  }
})
@posva
Copy link
Member

posva commented Apr 18, 2018

This was purposely removed (coerce) because it can be achieved with a computed property.
the sanitizer thing can actually be created as a plugin
You may find this FR to help: #7943

@posva posva closed this as completed Apr 18, 2018
@posva
Copy link
Member

posva commented Apr 18, 2018

I leveraged this behaviour in a small package: https://github.com/posva/vue-coerce-props in case you're interested 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants