Modifier `.trim`: Incompatible `trim()` when emit arg is not string
Vue version
3.2.39
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-qujitj?file=src/App.vue
Steps to reproduce
- Open the console
- Enter any value in the second input box
- Corresponding error occurs
What is expected?
- Trigger the emit function normally,
- If the arg value is incompatible with
trim()
, print a warning on the console
What is actually happening?
Uncaught TypeError: a.trim is not a function
System Info
No response
Any additional comments?
trim
modifier implementation
I think you should change $emit('update:modelValue', $event.target.value, {}) to $emit('update:modelValue', $event.target.value), because in this scenario the third parameter is completely redundant.
A warning should be triggered when the user sets a redundant parameter, while the redundant parameter can simply be ignored.
I think you should change $emit('update:modelValue', $event.target.value, {}) to $emit('update:modelValue', $event.target.value), because in this scenario the third parameter is completely redundant.
A warning should be triggered when the user sets a redundant parameter, while the redundant parameter can simply be ignored.
Thanks.
Yes, it is redundant in here, but what I really want to express is:
If the parameter type is not string, an error will directly cause the program to crash.
Moreover, although only one parameter is required in a controlled scenario, the emit
function supports multiple parameters.
so in my opinion, it should take into account the situation where the user uses modifiers .trim
and passes multiple parameters of different types
I think there are two ways:
- Inform the user that there are redundant parameters and only process the first parameter, I feel that this is not very good
- Make the corresponding return according to the type of the parameter,
trim()
of string type, other direct return, better i think
@zhangpaopao0609 duplicate https://github.com/vuejs/core/issues/5765
Duplicate of https://github.com/vuejs/core/issues/5765