[bug] The dynamic element(tag) can not apply the onChange events to `on`.
Closed this issue · 7 comments
like this:
const Tag = this.props.long ? "textarea" : "input"
const input = <Tag
onChange={this.props.onChange}
className="make-this-pretty"
id="important-input"
/>;
<input
v-if="type !== 'textarea'"
onChange={this.props.onChange}
className="make-this-pretty"
id="important-input"
/>
I know you can use dynamic attribute. But the question is for dynamic element(tag)
, not attribute.
The onChange
become to attrs
when the tag is dynamic.
sorry, I got the reason, stupid typo.
I know you can use dynamic attribute. But the question is for dynamic
element(tag)
, not attribute.The
onChange
become toattrs
when the tag is dynamic.
<input
v-if="type !== 'textarea'"
ref="input"
:type="newType"
:name="name"
:placeholder="placeholder"
:maxlength="maxlength"
:value="computedValue"
v-bind="$attrs"
onChange={this.props.onChange}
...
/>
export default {
inheritAttrs: false,
props: {
onChange: {
type: Function,
default: () => {}
}
}
}
Does component
work here?🤔
Yes, in fact it's not here, it should be in https://github.com/vuejs/jsx/tree/master/packages/babel-plugin-transform-vue-jsx/ .
Here just is tsx syntax checker. I've just found it.
jsx is still not very useful for complex component, such as: https://github.com/snowyu/qinputex
@snowyu also see this answer: vuejs/jsx-vue2#104 (comment)
very helpful!