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

v-model value must be a valid JavaScript member expression #3910

Closed
FabianSchwartau opened this issue Jun 8, 2021 · 7 comments
Closed

v-model value must be a valid JavaScript member expression #3910

FabianSchwartau opened this issue Jun 8, 2021 · 7 comments
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working

Comments

@FabianSchwartau
Copy link

FabianSchwartau commented Jun 8, 2021

Version

3.1.0-beta.6

Reproduction link

https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8cD57e3Rlc3REYXRhWzBdWzBdfX08L3A+XG4gIDxpbnB1dCB2LW1vZGVsPVwidGVzdERhdGFbMF1bMF1cIj5cbjwvdGVtcGxhdGU+XG5cbjxzY3JpcHQ+XG4gIGV4cG9ydCBkZWZhdWx0IHtcbiAgICBuYW1lOiAnYXBwJyxcbiAgICBkYXRhKCkge1xuICAgICAgcmV0dXJuIHtcbiAgICAgICAgdGVzdERhdGE6IFtbXCIxXCIsIFwiMlwiXSwgW1wiM1wiLCBcIjRcIl1dXG4gICAgICB9XG4gICAgfVxuICB9XG48L3NjcmlwdD5cbiJ9

Steps to reproduce

Access a 2D array with a v-model command in vue 3.1.0-beta6 and newer.

What is expected?

Access/model the element of the array without an error message.

What is actually happening?

It will throw an error telling you "v-model value must be a valid JavaScript member expression".


Interestingly this does not seem to be a problem with v-bind.
Earlier versions, including 3.0.11, are working just fine.
Has already been reported in #3891, but was closed due to missing example.

@lidlanca
Copy link
Contributor

lidlanca commented Jun 8, 2021

The fix #3675 for #3673 for the case of obj[x[0]]
regressed the case of obj[0][0]

@LinusBorg
Copy link
Member

/cc @HcySunYang

@HcySunYang
Copy link
Member

HcySunYang commented Jun 9, 2021

RegExp cannot cover all use cases, maybe it is more reasonable to use babel to check the validity of expressions, but considering the compiler in the browser environment, including babel is not a good solution.

@HcySunYang HcySunYang added 🐞 bug Something isn't working ❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. labels Jun 9, 2021
@HcySunYang
Copy link
Member

Made a PR

@lidlanca
Copy link
Contributor

lidlanca commented Jun 9, 2021

@HcySunYang
You are right the regexp approach is flawed

with the new pr this will fail.

isMemberExpression("a[b[c.d]][0]") => false 

if you can't use a parser to validate the expression,due to the concern of bundling babel in browser build
perhaps change it from an error to a development warning, so this will not be a blocker. for cases the regexp can't cover.

@whitespacecode
Copy link

whitespacecode commented Jul 1, 2021

@yyx990803 I updated to vue 3.1.2 and still get the error
[plugin:vite:vue] v-model value must be a valid JavaScript member expression.
My code:
<child-component v-model="form.options[lang][index]"></child-component >
I'm using compat build.

temporary work around i use

:value="form.options[lang][index]"
@change="(e) => form.options[lang][index] = e.target.value"

@posva
Copy link
Member

posva commented Jul 1, 2021

@JoeriTheGreat It seems to be working with the given example on this issue. Maybe it's a compat bug but I'm unsure if the compiler does a different work on compat mode

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ p4-important Priority 4: this fixes bugs that violate documented behavior, or significantly improves perf. 🐞 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants