Created
April 30, 2024 05:00
-
-
Save LuckyArdhika/87fd3a413dd3ce224ce008ff14fb4bcc to your computer and use it in GitHub Desktop.
To format normal input using getter and setter in model with computed function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script setup> | |
import { ref, computed } from 'vue' | |
const state = ref(20000); | |
const model = computed({ | |
get(){ | |
return state.value.toLocaleString(); | |
}, | |
set(v){ | |
state.value = !v ? 0: parseInt(v.replace(/,/g,'')); | |
} | |
}) | |
</script> | |
<template> | |
<h1>{{ state.toLocaleString() }}</h1> | |
<input v-model="model" /> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment