Examples of $watch usage in vue.js _javascript tips

Source: Internet
Author: User

Objective

Vue.js is a data-driven Web interface library. Vue.js is focused only on the view layer and can be easily consolidated with other libraries. Only 24kb after code compression

Vue.js provides a way to watch observe data changes on a Vue instance. Corresponding to an object, the key is an observation expression, and the value is the corresponding callback. The value can also be a method name, or an object, containing an option.

Called for each key at instantiation time$watch() ;

<template>
//Observation data is a string or array
<input v-model= "Example0"/>
<input v-model= "example1"/>< c4/>/When the single observation data Examples2 as the object, if the key value changes, in order to monitor the data changes, need to add deep:true parameters
<input v-model= "Example2.inner0"/>
</template>
<script>
Export Default {
data () {return
{
Exampl          E0: "",
example1: "",
example2:{
inner0:1,
innner1:2
}
}
,
watch:{
example0 (curval,oldval) {
Console.log        (curval,oldval);
example1: ' A ',//value can be methods method name
example2:{
//Note: When the observed data is an object or an array, curval and oldval are equal, Because the two parameters point to the same data object
handler (curval,oldval) {
conosle.log (curval,oldval)
},
    deep:true
}
,
methods:{
A (curval,oldval) {
con Osle.log (Curval,oldval)}}}
</script>

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, if you have questions you can message exchange.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.