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

Directives

All the v-* attributes in Vue are called directives, which is borrowed from Angular.

The concept of directives is very interesting. They make code easier to understand, easier to think about, and easier to work with.

There are other directives in Vue that we will use extensively throughout this book. For now, let's just list some of them: v-bind, v-cloak, v-for, v-else, v-else-if, v-model, v-on, v-oncev-text, and v-html.

An example of a useful directive is v-model. The v-model directive is used to make forms reactive; it helps us update data on user input events. While this topic might sound a bit advanced to a beginner in Vue, this complexity is dealt with so elegantly that even beginners should find it easy to see what is happening in the code:

<!-- HTML -->
<div id="app">
<span>Enter the weight in kilograms:</span>
<input v-model="someNum" type="number">
<div>The weight in pounds is: {{ someNum * 2.20 }}</div>
</div>

// js
new Vue({
el: '#app',
data() {
return {
someNum: "1"
}
}
})

As you can see, the {{ someNum }} value is bound to whatever a user types into the input field. In other words, the underlying data model—the value of someNum—will change based on user input.

To view the pen for the preceding example, visit https://codepen.io/AjdinImsirovic/pen/pKdPgX.

主站蜘蛛池模板: 定兴县| 三台县| 神池县| 凌云县| 兴宁市| 咸丰县| 闵行区| 舒城县| 安达市| 昭通市| 额济纳旗| 湾仔区| 巧家县| 房产| 威远县| 长兴县| 镇康县| 白朗县| 大兴区| 油尖旺区| 浦北县| 宁远县| 贞丰县| 偏关县| 浦东新区| 临高县| 徐州市| 桐庐县| 阜宁县| 曲松县| 四平市| 娄烦县| 汾西县| 临漳县| 保康县| 剑阁县| 贵阳市| 灵寿县| 温泉县| 察隅县| 织金县|