kouts / vue-modal

A customizable, stackable, and lightweight modal component for Vue.
https://vue-modal-demo.netlify.app/
MIT License
127 stars 16 forks source link

v-model does not work with JS expression #55

Closed TomDeSmet closed 2 years ago

TomDeSmet commented 2 years ago

If I use v-model with a Boolean variable, everything works fine: v-model="isOpen"

But If I use a JavaScript expression. Things fall apart: v-model="modalToOpenId === 'teamMemberX'"

I I put that same JavaScript expression in a computed and use that as the v-model variable, it works again. I have never seen this not working anywhere before, so I have no idea what is going on with it.

kouts commented 2 years ago

Hello @TomDeSmet, can you post a Stackblitz or a Codesandbox example of this? Could it be that the modalToOpenId is a Number and so the expression evaluates to false?

Antimated commented 2 years ago

@kouts I'm a team member of @TomDeSmet . the modalToOpenId is for sure a String. Outputting modalToOpenId === 'teamMemberX' evaluates to true or false. When we use a computed method like so:

    const test = computed(() => {
        return modalOpenId.value === 'modalTeamMember';
    })

and use test as the v-model it works as expected.

kouts commented 2 years ago

So the issue here is that v-model works with reactive values, not expressions. v-model keeps the value passed in sync with the internal value, in the expression's case how would it know which value to update? I guess this is a Vue thing and not a vue-modal issue and it's how it's expected to behave.

TomDeSmet commented 2 years ago

Sorry @kouts I guess my mind was already set to "holiday-mode" :)