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

  • Vue.js Quick Start Guide
  • Ajdin Imsirovic
  • 213字
  • 2021-06-24 18:23:56

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.

主站蜘蛛池模板: 来宾市| 沅陵县| 贵溪市| 惠来县| 汤阴县| 邹城市| 湖南省| 台安县| 闽侯县| 新河县| 保山市| 竹山县| 黑河市| 阿拉善盟| 静宁县| 渝北区| 新丰县| 邳州市| 保康县| 长海县| 博白县| 望奎县| 镇巴县| 甘南县| 循化| 长乐市| 格尔木市| 武陟县| 旺苍县| 城市| 昌乐县| 鲁甸县| 吴忠市| 武平县| 蓝山县| 封开县| 加查县| 诸城市| 阜南县| 霸州市| 循化|