vue之watch用法

來源:互聯網
上載者:User

標籤:調用   索引值   觀察   注意   回調   log   color   數組   pre   

對應一個對象,鍵是觀察運算式,值是對應回調。值也可以是方法名,或者是對象,包含選項。在執行個體化時為每個鍵調用 $watch();

vue單檔案組件寫法:
<
template>  //觀察資料為字串或數組   <input v-model="example0"/>   <input v-model="example1"/>  /當單觀察資料examples2為對象時,如果索引值發生變化,為了監聽到資料變化,需要添加deep:true參數   <input v-model="example2.inner0"/></template><script>   export default {      data(){        return {          example0:"",          example1:"",          example2:{            inner0:1,            innner1:2          }        }      },      watch:{        example0(curVal,oldVal){          console.log(curVal,oldVal);        },        example1:‘a‘,//值可以為methods的方法名        example2:{         //注意:當觀察的資料為對象或數組時,curVal和oldVal是相等的,因為這兩個形參指向的是同一個資料對象          handler(curVal,oldVal){            conosle.log(curVal,oldVal)          },          deep:true        }      },      methods:{        a(curVal,oldVal){          conosle.log(curVal,oldVal)        }      } }</script>

 

vue之watch用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.