[Vuejs]-Vue 3 radio button revert back if user canceled

0👍

Solved.

On input:

<input type="radio" :value="vf.id" name="defaultVersion" v-model="defaultValue" :checked="vf.id === defaultValue" @change="onChangeDefault(vf.id)" @click="onClickDefault">

Created a vmodel that hold the id for the default value

const defaultValue = ref(0)

// store the previous default value (id)
let previousDefault = 0
const onClickDefault = () => {
 previousDefault = defaultValue.value // this is the magic :)
}

the when the user canceled:

defaultValue.value = previousDefault

Leave a comment