组件的生命周期钩子函数:定义,当vue组件从创建到销毁这一系列的过程会有特定的步骤,这些特定的步骤,会回调特定的函数,我们把这些特定的不走成为组件的生命周期,我我们把组件的生命周期的回调函数,称为生命周期钩子函数
周期:
创建前后:beforeCreate创建前,created 创建完毕
渲染前后:beforeMount渲染前,*mounted渲染完毕
更新前后(多次执行):beforeUpdate更新前,updated更新完毕(data数据发生改变)
销毁前后:beforeDestory,destoryed(销毁定时器)销毁完毕
路由:
路由的参数:
$route.params路由配置的参数 $route.query路由的查询参数 $route.path路由的地址 $route.name
编程路由跳转:
$router.go(-1)历史记录前进后退(前进forward 返回 back)
$router.push("/")地址跳转
$router.replace("/")跳转不留历史记录
基本路由:
1,配置:
{
path:"/about",
name:‘about’,
component:About
}
2,切换:
关于
$router.push("/about")
KaTeX parse error: Expected '}', got 'EOF' at end of input: …k> 3. 获取路由参数 {{route.params.id}}
子路由:
- 配置
{path:"/detail",name:“detail”,component:Detail,
children:[
{path:“arg”,component:Arg},
{path:“comment”,component:Comment},
{path:" ",redirect:“arg”},
]
} - 切换
商品 - 子路由设置 Detail.vue