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 is invalid in vue@next with vite #39

Closed
Tan90Qian opened this issue May 3, 2020 · 4 comments
Closed

v-model is invalid in vue@next with vite #39

Tan90Qian opened this issue May 3, 2020 · 4 comments

Comments

@Tan90Qian
Copy link

In a project created with vite, I define a component with model such as:

<template>
  <input
    type="checkbox"
    v-bind:checked="checked"
    v-on:change="$emit('change', $event.target.checked)"
  />
</template>
<script>
export default {
  name: "BaseCheckbox"
  model: {
    prop: "checked",
    event: "change",
  },
  props: {
    checked: Boolean,
  },
};
</script>

and then I use v-model to bind checked for BaseCheckbox

<template>
  <BaseCheckbox v-model="checked" />
</template>

<script>
export default {
  data: () => ({checked: true})
}
</script>

It didn't work, and the value of checked props was false in BaseCheckbox.But v-model with native dom was running normal.
Is this problem about vite, vue@next or compiler?

@sqal
Copy link

sqal commented May 3, 2020

@Tan90Qian
Copy link
Author

So this is an incompatible change? If I have a custom component base on Vue@2 and I want to use it in a project base on Vue@next, I need to refactor it at first?

@sqal
Copy link

sqal commented May 3, 2020

I think you can make it work in both versions of Vue. You need to add this.$emit('update:modelValue, value) where you emitting change event, however you have to handle the modifiers by yourself by checking if modelModifiers prop exists

@yyx990803
Copy link
Member

Please read RFCs for Vue core changes. This is not a vite issue.

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

No branches or pull requests

3 participants