- Vue.js 2 Web Development Projects
- Guillaume Chau
- 176字
- 2021-07-02 22:34:24
Adding basic interactivity with directives
Let's add some interactivity to our otherwise quite static app, for example, a text input that will allow the user to change the message displayed. We can do that in templates with special HTML attributes called directives.
All the directives in Vue start with v- and follow the kebab-case syntax. That means you should separate the words with a dash. Remember that HTML attributes are case insensitive (whether they are uppercase or lowercase doesn't matter).
The directive we need here is v-model, which will bind the value of our <input> element with our message data property. Add a new <input> element with the v-model="message" attribute inside the template:
<p id="root">
<p>{{ message }}</p>
<!-- New text input -->
<input v-model="message" />
</p>
Vue will now update the message property automatically when the input value changes. You can play with the content of the input to verify that the text updates as you type and the value in the devtools changes:

There are many more directives available in Vue, and you can even create your own. Don't worry, we will cover that in later chapters.
- MySQL數據庫管理實戰
- Java多線程編程實戰指南:設計模式篇(第2版)
- Production Ready OpenStack:Recipes for Successful Environments
- C語言程序設計立體化案例教程
- Python 3破冰人工智能:從入門到實戰
- Android程序設計基礎
- 從Java到Web程序設計教程
- Unity 3D/2D移動開發實戰教程
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- Microsoft Exchange Server 2016 PowerShell Cookbook(Fourth Edition)
- jQuery Mobile Web Development Essentials(Second Edition)
- Ionic3與CodePush初探:支持跨平臺與熱更新的App開發技術
- 算法訓練營:海量圖解+競賽刷題(入門篇)
- 微信公眾平臺開發最佳實踐
- Java程序設計基礎教程