- 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-once, v-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.
- 計算機網絡與通信(第2版)
- Application Development with Qt Creator(Second Edition)
- Hands-On Chatbots and Conversational UI Development
- 計算機網絡安全實訓教程(第二版)
- 網絡安全技術與解決方案(修訂版)
- 物聯網與無線傳感器網絡
- 物聯網通信技術
- OMNeT++與網絡仿真
- Hands-On Microservices with Node.js
- AWS Lambda Quick Start Guide
- 移動物聯網:商業模式+案例分析+應用實戰
- 5G非正交多址接入技術:理論、算法與實現
- 現場綜合化網絡運營與維護:運營商數字化轉型技術與實踐
- 物聯網
- 通信系統實戰筆記:無處不在的信號處理