mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
fix(plugin-jsx): v-model argument and modifier co-usage (#668)
This commit is contained in:
parent
55bab7a081
commit
d352b5849f
@ -162,10 +162,14 @@ const App = {
|
||||
|
||||
```jsx
|
||||
<input v-model={[val, ['modifier']]} />
|
||||
// 或者
|
||||
<input v-model_modifier={val} />
|
||||
```
|
||||
|
||||
```jsx
|
||||
<A v-model={[val, 'argument', ['modifier']]} />
|
||||
// 或者
|
||||
<input v-model:argument_modifier={val} />
|
||||
```
|
||||
|
||||
会编译成:
|
||||
|
@ -166,10 +166,14 @@ const App = {
|
||||
|
||||
```jsx
|
||||
<input v-model={[val, ['modifier']]} />
|
||||
// Or
|
||||
<input v-model_modifier={val} />
|
||||
```
|
||||
|
||||
```jsx
|
||||
<A v-model={[val, 'argument', ['modifier']]} />
|
||||
// Or
|
||||
<input v-model:argument_modifier={val} />
|
||||
```
|
||||
|
||||
Will compile to:
|
||||
|
@ -67,7 +67,7 @@ const parseDirectives = (params: {
|
||||
.replace(/^\S/, (s: string) => s.toLowerCase());
|
||||
|
||||
if (directiveArgument) {
|
||||
args.push(t.stringLiteral(directiveArgument));
|
||||
args.push(t.stringLiteral(directiveArgument.split('_')[0]));
|
||||
}
|
||||
|
||||
const isVModels = directiveName === 'models';
|
||||
|
@ -286,3 +286,48 @@ test('Named model', async () => {
|
||||
await wrapper.trigger('click');
|
||||
expect(wrapper.html()).toBe('<div>2</div>');
|
||||
});
|
||||
|
||||
test('named model and underscore modifier should work in custom component', async () => {
|
||||
const Child = defineComponent({
|
||||
emits: ['update:value'],
|
||||
props: {
|
||||
value: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
},
|
||||
valueModifiers: {
|
||||
default: () => ({ double: false }),
|
||||
},
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const handleClick = () => {
|
||||
emit('update:value', 3);
|
||||
};
|
||||
return () => (
|
||||
<div onClick={handleClick}>
|
||||
{props.valueModifiers.double ? props.value * 2 : props.value}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
data() {
|
||||
return {
|
||||
foo: 1,
|
||||
};
|
||||
},
|
||||
render() {
|
||||
return <Child v-model:value_double={this.foo} />;
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
expect(wrapper.html()).toBe('<div>2</div>');
|
||||
wrapper.vm.$data.foo += 1;
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(wrapper.html()).toBe('<div>4</div>');
|
||||
await wrapper.trigger('click');
|
||||
expect(wrapper.html()).toBe('<div>6</div>');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user