官术网_书友最值得收藏!

Displaying text

The first template feature we will see is the text interpolation, which is used to display dynamic text inside our web page. The text interpolation syntax is a pair of double curly braces containing a JavaScript expression of any kind. Its result will replace the interpolation when Vue will process the template. Replace the <p id="root"> element with the following:

<p id="root">
<p>{{ message }}</p>
</p>

The template in this example has a <p> element whose content is the result of the message JavaScript expression. It will return the value of the message attribute of our instance. You should now have a new text displayed on your web page--Hello Vue.js!. It doesn't seem like much, but Vue has done a lot of work for us here--we now have the DOM wired with our data.

To demonstrate this, open your browser console and change the app.message value and press Enter on the keyboard:

app.message = 'Awesome!'

The message has changed. This is called data-binding. It means that Vue is able to automatically update the DOM whenever your data changes without requiring anything from your part. The library includes a very powerful and efficient reactivity system that keeps track of all your data and is able to update what's needed when something changes. All of this is very fast indeed.

主站蜘蛛池模板: 凤阳县| 昭通市| 锦屏县| 闻喜县| 禄劝| 南充市| 华宁县| 兖州市| 额尔古纳市| 麻栗坡县| 北票市| 临湘市| 额敏县| 江安县| 九寨沟县| 武威市| 襄汾县| 荣昌县| 屯留县| 桂平市| 府谷县| 尼勒克县| 乐清市| 庆元县| 武汉市| 且末县| 福海县| 普洱| 平阳县| 泽库县| 隆尧县| 尤溪县| 庆安县| 塔河县| 卓资县| 延吉市| 达拉特旗| 惠安县| 三河市| 鸡泽县| 平凉市|