老师讲错了了吧?
来源:5-3 Vue3数据绑定显示列表数据

没野心的狼
2022-07-26
Vue 官方说Because setup is run around the beforeCreate and created lifecycle hooks, you do not need to explicitly define them. In other words, any code that would be written inside those hooks should be written directly in the setup function.所以axios请求应该直接写在setup 里,onMounted 是在组件渲染到页面执行的,显然不应该把axios 代码写在这里。
写回答
1回答
-
甲蛙
2022-07-26
不清楚你指的是我讲的哪一段,setup和onMounted都是初始化,只不过onMounted是等组件都准备好了再执行。axios一般是去后端取数据用的,放在setup和onMounted都可以。
022022-12-01
相似问题