Skip to content

v-model on a custom element #1699

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Benoit-Vasseur opened this issue Jul 24, 2020 · 1 comment
Closed

v-model on a custom element #1699

Benoit-Vasseur opened this issue Jul 24, 2020 · 1 comment

Comments

@Benoit-Vasseur
Copy link

Benoit-Vasseur commented Jul 24, 2020

Version

3.0.0-rc.4

Reproduction link

https://github.com/Benoit-Vasseur/bug-vue3-v-model-wc

Steps to reproduce

  • npm run dev

What is expected?

  • no error in compilation
  • v-model is working if the web component is using value prop and trigger the 'input' event

What is actually happening?

  • compilation is failing : [vite] SFC template compilation error: v-model can only be used on <input>, <textarea> and <select> elements.

I based my test on those RFCs :

vueCompilerOptions.isCustomElement seems to work but when i tried to add the v-model attribute it break the compilation :/.

I tried to read the compiler code to find a way to alter the tag of the node, but it does not seem possible : https://github.com/vuejs/vue-next/blob/master/packages/compiler-dom/src/transforms/vModel.ts#L47

Issue for vue2 is here : vuejs/vue#7830

I am open to try to make a PR for this if you give me some hints to implement the feature :).

Thank you in advance for your reply.
Can not wait to adopt Vue 3 :).

@Benoit-Vasseur
Copy link
Author

Thanks :).

I was developping this and wanted to make a PR but it is done so it is perfect :).
However I have a suggestion concerning the v-model on a custom element.
I think it could be safer to force the "type" and name the prop v-model-type instead of type. type looks to dangerous to me for the naming collision. I was also thinking of <my-element v-model="model" v-model.type="text" /> but I do not think that it respect the design of the modifier, it is more an "adder" in this case.

What do you think (rename type to v-model-type and make it mandatory for custom element with a proper error message) ? I can make a PR if you approve the idea :).

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant