JSFiddle - React, Tailwind, and code Playground
by skirtle
HTML
<script src="https://unpkg.com/[email protected]/dist/vue.global.js"></script>
<div id="app">
<div v-if="first">
<button ref="btn" @click="first = false">
First
</button>
</div>
<div v-else>
<button ref="btn" @click="first = true">
Second
</button>
</div>
</div>
JavaScript
Vue.createApp({
setup () {
const btn = Vue.ref(null)
const first = Vue.ref(true)
return {
btn,
first
}
},
updated () {
console.log('updated: ' + this.btn.innerHTML.trim())
},
watch: {
btn: {
flush: 'pre',
handler () {
console.log('btn changed: ' + this.btn.innerHTML.trim())
}
}
}
}).mount('#app')