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

calling methods is not allowed in v-model #3993

Closed
jacekkarczmarczyk opened this issue Jun 22, 2021 · 5 comments
Closed

calling methods is not allowed in v-model #3993

jacekkarczmarczyk opened this issue Jun 22, 2021 · 5 comments

Comments

@jacekkarczmarczyk
Copy link
Contributor

jacekkarczmarczyk commented Jun 22, 2021

Version

3.1.2

Reproduction link

Vue 3 - not working:

sfc.vuejs.org

Vue 2 - working:

https://codepen.io/jkarczm/pen/ZEeNNPW?editors=1010

Steps to reproduce

<input v-model="whatever().something">

What is expected?

No compilation error

What is actually happening?

v-model value must be a valid JavaScript member expression.

@lidlanca
Copy link
Contributor

lidlanca commented Jun 22, 2021

some improvements were made in (bc100c5 )
to cover more valid expressions, but it does not cover all valid member expressions.
like the one you encountered.

<input v-model="what().ever">

if your function does not have dynamic arguments, you can wrap the function in a computed

what = computed( ()=> whatever())
<input v-model="what.ever">

if you do have dynamic arguments, it will complicate things to work around that limitation.

@jacekkarczmarczyk
Copy link
Contributor Author

if you function does not have dynamic arguments, you can wrap the function in a computed

Yeah, but if it has and they come from v-for (like in the example in my comment in the mentioned commit) i can't use computed.
I wonder why do we even need this check, vue doesn't check if you have proper expression in v-bind:foo or in mustaches, you're just getting a syntax or runtime error, why it's not enough in v-model?

@lidlanca
Copy link
Contributor

and here is a possible workaround if you really need dynamic arguments

https://sfc-vue3.netlify.app/#/gist/c1242a00f99d8a3ed26cb002303dfcca

I originally recommended reducing that to a development warning and not an error.
due to incomplete validation.

@shadoWalker89
Copy link

Using the return value of a function in v-model used to work in vue 2.
I encountered this problem after upgrading my app to vue 3

@vricosti
Copy link

vricosti commented Jul 15, 2021

Same problem here:

    <input
      type="text"
      v-model="getValuesMarginMin()[0]"
      :class="'entry '+getUserInputStatusClass(getValuesMarginMin()[3])"
      disabled
    />
</td>

`export default {
store: store,
name: "ValuesConstraintsMarginUnit",
mixins: [HtmlAdapter],

props: {
labels: {
type: Array,
default: function() {
return [];
}
},
values: {
type: Array,
default: function() {
return [];
}
},
},
methods: {
getValuesMarginMin() {
return this.values[0];
},
...`

@github-actions github-actions bot locked and limited conversation to collaborators Oct 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants