美文网首页
3.3 Vue的生命周期

3.3 Vue的生命周期

作者: panw3i | 来源:发表于2018-05-27 19:53 被阅读4次
    
    import Vue from 'vue'
    
    const app = new Vue({
      // el: '#root',
      // template: '<div>{{text}}</div>',
      data: {
        text: 0
      },
      beforeCreate () {
        console.log(this.$el, 'beforeCreate')
      },
    
    // 可以放置与数据相关的操作
      created () {
        console.log(this.$el, 'created')
      },
      beforeMount () {
        console.log(this.$el, 'beforeMount')
      },
    
    //  可以进行节点渲染后的DOM操作
      mounted () {
        console.log(this.$el, 'mounted')
      },
      beforeUpdate () {
        console.log(this, 'beforeUpdate')
      },
      updated () {
        console.log(this, 'updated')
      },
    
    // 与内置的 keep-alive 组件相关的钩子函数
      activated () {
        console.log(this, 'activated')
      },
      deactivated () { 
        console.log(this, 'deactivated')
      },
    
    
      beforeDestroy () {
        console.log(this, 'beforeDestroy')
      },
      destroyed () {
        console.log(this, 'destroyed')
      },
      render (h) {
        throw new TypeError('render error')
        // console.log('render function invoked')
        // return h('div', {}, this.text)
      },
      renderError (h, err) {
        return h('div', {}, err.stack)
      },
      errorCaptured () {
        // 会向上冒泡,并且正式环境可以使用
      }
    })
    
    app.$mount('#root')
    // setInterval(() => {
    //   app.text = app.text += 1
    // }, 1000)
    
    setTimeout(() => {
      app.$destroy()
    }, 1000)
    
    

    相关文章

      网友评论

          本文标题:3.3 Vue的生命周期

          本文链接:https://www.haomeiwen.com/subject/mzhijftx.html