Skip to content

Instantly share code, notes, and snippets.

@LuckyArdhika
Created April 30, 2024 05:00
Show Gist options
  • Save LuckyArdhika/87fd3a413dd3ce224ce008ff14fb4bcc to your computer and use it in GitHub Desktop.
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
<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