替代 Options API的写法
ue3转变
从 vue3 开始,由 setup 替代 vue2 data、methods、watch等 ,这样可以避免一个功能的代码逻辑拆分到各个属性中而变得难以阅读
vue3 setup 的这种写法可以更好的使用 TypeScript
注意事项:
setup 函数里面不可以使用 this, 因为setup里面没有绑定 this
setup(){console.log(this)}; // undefined
setup 里面定义的数据默认不是响应式的,即数据发生改变,但是页面数据不刷新。需要使用 ref reactive 等响应式API