美文网首页
@芥末的糖-----生命周期

@芥末的糖-----生命周期

作者: 芥末的糖 | 来源:发表于2018-12-08 14:42 被阅读0次

    以下代码直接运行,看console,就秒懂,别的就不BB了

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
      <title>Vue.js-lifecycle</title>
      <script src="../vue.js"></script>
      
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    
    </head>
    <body>
      <div id="root">
        <div>{{ greeting }}</div>
      </div>
      <script>
        Vue.config.productionTip = false
        const vm = new Vue({
          el: '#root',
          data: {
            greeting: 'hello'
          },
          // 初始化时期
          beforeCreate () {
            console.log(this.$el)
            console.log(this.greeting)
          },
          created () {
            console.log(this.$el)
            console.log(this.greeting)
          },
          
          // 创建时期
          beforeMount () {
            console.log(this.$el.innerHTML)
            console.log(this.greeting)
          },
          mounted () {
            console.log(this.$el.innerHTML)
            console.log(this.greeting)
          },
    
          // 生存期
          beforeUpdate () {
            console.log('beforeUpdate:' + this.greeting)
          },
          updated () {
            console.log('updated:' + this.greeting)
          },
    
          // 销毁期
          beforeDestroy () {
            console.log('beforeDestroy:' + this.greeting)
          },
          destroyed () {
            console.log('destroyed:' + this.greeting)
          }
        })
      </script>
    </body>
    </html>
    ------------------------------------
    undefined
    undefined
    undefined
    hello
    <div>{{ greeting }}</div>
    hello
    <div>hello</div>
    hello
    

    记得结合这张图!

    z.png

    如果再不懂就放弃吧!!!

    相关文章

      网友评论

          本文标题:@芥末的糖-----生命周期

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