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

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.

主站蜘蛛池模板: 呼伦贝尔市| 蛟河市| 惠东县| 伊宁县| 遵义县| 蓬莱市| 英超| 合川市| 吴川市| 武安市| 荥经县| 辽宁省| 贵南县| 蒙阴县| 邯郸市| 蒙城县| 游戏| 濮阳市| 白河县| 馆陶县| 修水县| 三江| 黑水县| 太仓市| 潢川县| 沁阳市| 荣昌县| 多伦县| 武穴市| 阿拉尔市| 樟树市| 信阳市| 郧西县| 察雅县| 通辽市| 左云县| 永济市| 六枝特区| 伊宁市| 独山县| 永康市|