8000 useVModel => defineModel upgrade · Issue #1799 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content
useVModel => defineModel upgrade #1799
Closed
@VividLemon

Description

@VividLemon

Clear and concise description of the problem

We want to upgrade to defineModel. useVModel syntax needs to adjust to this

const props = withDefaults(defineProps<{modelValue?: string}>(), {modelValue: '123'})
const emit = defineEmits<{ 'update:modelValue': [string]}>()

const modelVal = useVModel(props, 'modelValue', emit, {passive: true})

=>

const modelVal = defineModel<string>({default: '123'})

There shouldn't be any unexpected breaking changes. I'm pretty sure the two should behave identically

Lastly, I believe this can adjust the workflow for BFormInput. We can explicitly define the modifiers, and create more straightforward syntax for modifiers. https://vuejs.org/api/sfc-script-setup.html#modifiers-and-transformers

const [modelValue, modelModifiers] = defineModel<string, 'trim' | 'number'>({
  // get() omitted as it is not needed here
  set(value) {
    // if the .trim modifier is used, return trimmed value
    if (modelModifiers.trim) {
      return value.trim()
    }
    if(modelModifiers.number) {
      //
    }
    // otherwise, return the value as-is
    return value
  }
})

etc etc

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0