In this example, we create a Vue component vm
to show weather information. Two data properties of the component object, temperature
and rain
are displayed in the HTML template using the mustache notation {{ property }}
. An important feature of Vue is reactivity. When a property in data
changes, Vue will update the HTML content generated from the properties.
We can also bind an HTML attribute (e.g. src
of <img>
) using the Vue directive v-bind:attr
. In this example, we write v-bind:src="conditionURL"
or :src="conditionURL"
to bind the image URL attribute src
to the data property conditionURL
. If the property changes, Vue will automatically update the HTML attribute.
Try the following
vm.temperature
, vm.rain
, etcvm.conditionURL='image/sunny.png'
data
property looks complicated at first. You need to define a function that returns a JavaScript object containing the properties of your component instance.humidity
to the component. Add HTML code to show the property in the template.