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

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.

主站蜘蛛池模板: 灵丘县| 尼玛县| 广元市| 方正县| 京山县| 临夏市| 襄垣县| 泾阳县| 奎屯市| 中江县| 浏阳市| 牡丹江市| 麻江县| 广元市| 莱阳市| 杭锦旗| 张掖市| 蓬安县| 卢氏县| 盐山县| 遂平县| 延庆县| 龙陵县| 铁岭县| 灵山县| 庆元县| 花莲市| 白朗县| 茌平县| 岳普湖县| 乌兰察布市| 汉阴县| 万全县| 东乌珠穆沁旗| 金川县| 阜平县| 康保县| 霸州市| 军事| 大丰市| 盖州市|