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

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.

主站蜘蛛池模板: 定日县| 阿拉善左旗| 合山市| 大足县| 沾益县| 渝北区| 嘉鱼县| 西丰县| 五寨县| 通化市| 红桥区| 昭苏县| 盐城市| 定兴县| 宜宾市| 赫章县| 巴中市| 搜索| 雷山县| 济南市| 米泉市| 临安市| 巫山县| 中宁县| 通化市| 文成县| 岳阳市| 和硕县| 贵德县| 松阳县| 淮阳县| 双江| 延吉市| 犍为县| 海口市| 新津县| 商城县| 安乡县| 商水县| 天全县| 石渠县|