vue組件生有哪些命周期

本篇文章給大家分享的是有關(guān)vue組件生有哪些命周期,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

10余年的汨羅網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。網(wǎng)絡(luò)營銷推廣的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整汨羅建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)建站從事“汨羅網(wǎng)站設(shè)計”,“汨羅網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。

具體內(nèi)容如下

分為4個階段:

create/mount/update/destroy

每一個階段都對應(yīng)著有自己的處理函數(shù)

create: beforeCreate created

初始化

mount: beforeMount mounted

和掛載相關(guān)的處理

update: beforeUpdate updated

根據(jù)要更新的數(shù)據(jù) 做邏輯判斷

destroy:beforeDestroy destroyed

清理工作

代碼:

<!doctype html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>生命周期</title>
 <script src="js/vue.js"></script>
 </head>
 <body>
 <div id="container">
  <p>{{msg}}</p>
<!--點擊的時候isShow進行取反 -->
  <button @click="isShow = !isShow">切換是否顯示組件</button>
  <my-component v-if="isShow"></my-component>
 </div>
 <script>
  Vue.component("my-component",{
   template:`
     <div>
      <button @click="handleClick">Click Me</button>
      <h2>component:{{count}}</h2>
      </div>
   `,
   data:function(){
     return {
      count:0
     }
    },
   methods:{
    handleClick:function(){
     this.count++;
    }
   },
   beforeCreate: function () {
   console.log('準(zhǔn)備創(chuàng)建組件');
  },
  created: function () {
   console.log('組件創(chuàng)建完畢');
  },
  beforeMount: function () {
   console.log('組件的模板準(zhǔn)備掛載到DOM');
  },
  mounted: function () {
   console.log('掛載完畢');
  },
  beforeUpdate: function () {
   console.log('準(zhǔn)備更新了');
  },
  updated:function(){
   console.log('更新完成');
  },
  beforeDestroy: function () {
   console.log('準(zhǔn)備destroy');
  },
  destroyed: function () {
   console.log('destroy完成');
  }
  })
  new Vue({
   el:"#container",
   data:{
    msg:"Hello VueJs",
    isShow:true
   }
  })
 </script>
 </body>
</html>

生命周期練習(xí),需要那階段寫那個階段

<!doctype html>
<html>
 <head>
 <meta charset="UTF-8">
 <title>生命周期練習(xí)</title>
 <script src="js/vue.js"></script>
 </head>
 <body>
 <div id="container">
  <p>{{msg}}</p>
  <my-component></my-component>
 </div>
 <script>
  Vue.component("my-component",{
   data:function(){
    return {
     myOpacity:0
    }
   },
   template:` <h2 v-bind:>透明度將改變
   </h2>`,
   mounted:function(){
    setInterval(function(){
     this.myOpacity += 0.1;
     if(this.myOpacity>1){
      this.myOpacity = 0;
     }
    }.bind(this),1000)
   }
  })
  new Vue({
   el:"#container",
   data:{
    msg:"Hello VueJs"
   }
  })
 </script>
 </body>
</html>

以上就是vue組件生有哪些命周期,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

本文題目:vue組件生有哪些命周期
當(dāng)前地址:http://muchs.cn/article44/ighihe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、外貿(mào)建站響應(yīng)式網(wǎng)站、微信小程序網(wǎng)站內(nèi)鏈、App設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)