Vue: [improvement]Allow usage of event modifiers on functional component events

Created on 24 Nov 2016  ·  2Comments  ·  Source: vuejs/vue

To stop event propagation in functional components I have to include dirty piece of DOMEvent code in form of:

attrs: {
    role: 'button',
    alt: __('reset_to_default_value'),
    title: __('reset_to_default_value'),
    'onclick': 'event.stopPropagation()'
},
on: {
    click: context.parent.resetValue
}

it would be really neat if we could use standard vue's event modifiers known from standard templates,
perhaps in form of (to keep the syntax similar to existing watch syntax):

on: {
    click: {
        stop:true, 
        prevent:true,
        handler: context.parent.resetValue
    }
}

Most helpful comment

it's up to the click function to control that:

on: {
  click (event) {
    event.stopPropagation()
    context.parent.resetValue(event)
  }
}

Adding those attrs will just do magically the same for you (if the feature was implemented)

All 2 comments

it's up to the click function to control that:

on: {
  click (event) {
    event.stopPropagation()
    context.parent.resetValue(event)
  }
}

Adding those attrs will just do magically the same for you (if the feature was implemented)

Wow, just wow.

I was so trapped inside particular way of thinking about it I've missed the obvious solution, thank You @posva 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guan6 picture guan6  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments

seemsindie picture seemsindie  ·  3Comments

finico picture finico  ·  3Comments

bdedardel picture bdedardel  ·  3Comments