nuxt.js使用教程
1.Nuxt生命周期
request -> nuxtServerInit -> middleware -> validate() -> asyncData & fetch() -> render -> vue周期(客户端)
运行在服务器的钩子:
-
nuxtServerInit
-
middleware
-
validate
-
asyncData & fetch
服务器端的钩子拿不到客户端的数据
注意:beforeCreate 和 create两个钩子,会运行在服务端和客户端;
运行在客户端的钩子:
-
beforeMounte
-
mounted
-
beforeUpdate
-
Updated
-
beforeDestroy
-
destroy
跑在客户端的钩子,都可以通过context访问到服务器端的数据
context包括:isDev, route, store, env, params, query, req, res, redirect, error