目录
一、vue3
<script>
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup() {
const count = ref(2)
const add = () => {
count.value += 1
}
return {
count,
add,
}
}
})
</script>
总结:定义的变量要return出去才能用
二、vue3.2
<script setup>
import { ref } from 'vue'
const count = ref(2)
const add = () => {
count.value += 1
}
</script>
总结:vue3.2使用setup这个语法糖 成功的简化了vue3的一些代码, 直接定义的变量不许要return就直接能使用