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

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.

主站蜘蛛池模板: 永胜县| 庆元县| 若尔盖县| 油尖旺区| 广水市| 若羌县| 松潘县| 桦川县| 古丈县| 广德县| 绵阳市| 庐江县| 同仁县| 高密市| 佛教| 信丰县| 平塘县| 承德县| 竹溪县| 阳泉市| 天津市| 桂平市| 沙田区| 乐东| 濮阳市| 青神县| 贺兰县| 涞水县| 松阳县| 浙江省| 洪泽县| 通州区| 中宁县| 从化市| 获嘉县| 隆回县| 山西省| 镇坪县| 彝良县| 商城县| 六安市|