同样是完成点击自增
Vue2:
<button @click="addCount">{{count}}</button>
<script>
export defult{
data(){
return{
count:0
}
},
methods:{
addCount(){
this.count ++
}
}
}
</script>
Vue3:
<button @click="addCount">{{count}}</button>
<script setup>
import {ref} from 'vue'
const count=ref(0)
const addCount =()=>count.value++
</script>
vue2->vue3 分散式维护变为集中式维护
vue3:API开发更为简洁,但别忘了在script里加setup,定义数用ref,要记得引入ref