v-model.number
not working if using :model-value
and @update:model-value
#8605
Answered
by
dpschen
frederikheld
asked this question in
Help/Questions
-
Hey everyone, it is possible to define the <script setup>
import { ref, watch } from 'vue'
const currentValue = ref(0)
watch(currentValue, () => {
console.log(currentValue.value, typeof currentValue.value) // `typeof currentValue.value === 'number'`
})
</script>
<template>
<input
v-model.number="currentValue"
/>
</template> I would like to do the same when using [...]
console.log(currentValue.value, typeof currentValue.value) // `typeof currentValue.value === 'string'`
[...]
<input
:model-value.number="currentValue"
@update:model-value="value => currentValue = value"
/>
[...] Is this possible? If not, how would you approach this? |
Beta Was this translation helpful? Give feedback.
Answered by
dpschen
Jun 29, 2023
Replies: 1 comment 1 reply
-
Use the This is the same function used in the v-model directive. <template>
<input
:model-value.number="currentValue"
@update:model-value="value => currentValue = looseToNumber(value)"
/>
</template>
<script setup>
import { looseToNumber } from '@vue/shared'
</script> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
frederikheld
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the
looseToNumber
function manually.This is the same function used in the v-model directive.