question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useVModel(s) should optionally be backwards compatible.

See original GitHub issue

Clear and concise description of the problem

I would like to create a runtime bridge for v-model to work with Vue 2.X and Vue 3 components. Vue Bridge wants to solve this problem, but is not currently publicized heavily as it is under construction.

I believe VueUse would have better adoption + usage due to its popularity and it already depends on vue-demi.

Is this out of scope?

Suggested solution

In VueUse core, we could extend useVModel to take in an option for backwards compatibility.

As an aside: I would like Volar + vue-tsc to help create a version of defineProps and defineEmits that would support this macro. Is an experimental feature possible @johnsoncodehk? I think I will create an issue in either project (vue-tsc || Volar) regardless of if we end up adding this functionality to VueUse.

Alternative

  • We could create a separate function so that useVModel is not weighed down by a heavier API surface area.
  • We could decide this is out of scope for VueUse

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
JessicaSachscommented, Oct 12, 2022

Yes! It’s almost there, but the open issues block me from using it. Can you double check my usage?

Blockers:

  1. Does not seem to work with Vue 2.7. Can you check if I am doing it right?
    1. Here is a video and reproduction and a High-resolution video download
      Low-res gif of Vue 2.7 not working with modelValue
  2. TypeScript / Volar is not supported (written in the known issues, but this breaks all prop-type checking).
  3. withDefaults not supported

Reproducing:

pnpm install
pnpm dev:2 # Vue 2 development
pnpm dev:3 # Vue 3 development
  1. vite.config.ts is specific to Vue 2 + Vue 3, with a shared common.
  2. Source + Test are symlinked across Vue versions. (This architecture is based on Vue Bridge’s)

Pros:

  1. Doing a build-time transform instead of explicit runtime logic would be very nice!!!
  2. Unplugin ecosystem makes this accessible for lots of users 👍
1reaction
sxzzcommented, Oct 16, 2022

@JessicaSachs Hi, I already added the support of Vue 2 and the unified prop name. It will transform Vue 3 code to Vue 2 seamless. I also already refactored the code of your project. So just go to check code~ https://github.com/JessicaSachs/petite/compare/v-model-support...sxzz:petite:v-model-support

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backward Compatibility Rules - Specmatic
If consumers choose to send the key, the server will now ignore it, which could break consumers assumptions. Optional key becomes mandatory, incompatible ......
Read more >
What is Backward Compatible (Backward Compatibility)?
Explore backward compatible hardware and software that can use interfaces and data from earlier versions. Consider examples, pros and cons and the future....
Read more >
wsdl - Backward compatible change of a web service API?
To answer your question – it depends. My research over the net tells me that allowing the new optional parameters in response should...
Read more >
Q&A: Backward Compatibility for APIs - Embedded Artistry
A rough rule of thumb for maintaining backward compatibility is to never ... If you need to expand a function's parameters, add optional ......
Read more >
useVModel - VueUse
import { useVModel } from '@vueuse/core' export default { setup(props, { emit }) { const data = useVModel(props, 'data', emit) console.log(data.value) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found