动态路由的传值~生命周期~闭包~订阅

52 阅读1分钟

1.动态路由传值使用

created ,inject 用这个因为这个方法用好用

2.跳转是 query

this.$router.push() 和 标签 router-link 里面的 to 写上路由进行跳转等

3.生命周期 首选先是可以分成两个阶段 一个是16.4之前的:

三个阶段

加载阶段
  constructor
  render
  componentDidMount
更新阶段
  shouldComponentUpdate(nextProps, nextState)
    return false 组件不渲染
    return true 组件才会渲染
  render
  componentDidUpdate
卸载阶段
  componentWillUnmount

一个是16.4之后的:

三个阶段

加载阶段
  constructor
  getDerivedStateFromProps
  render
  componentDidMount

更新阶段
  getDerivedStateFromProps
  shouldComponentUpdate(nextProps, nextState)
      return false 组件不渲染
      return true 组件才会渲染
  render
  getSnapshotBeforeUpdate
  componentDidUpdate

卸载阶段
  componentWillUnmount

image.png

4.闭包

可以访问函数里面的数据的函数

好处是可以避免造成的全局的污染

缺点是可能会造成内存溢出

5.订阅~发布

image.png image.png