- Vue.js Quick Start Guide
- Ajdin Imsirovic
- 206字
- 2021-06-24 18:23:56
Modifiers
The directives in Vue are further extended with the help of modifiers.
The link to official documentation on modifiers in directives can be found at this link: https://vuejs.org/v2/guide/forms.html#Modifiers.
To use a modifier, we simply append it to a directive. The simplest possible example might look a bit like this:
<!-- HTML -->
<div>
<input v-model.trim="userInput" placeholder="type here">
<p>You have typed in: {{ userInput }}</p>
</div>
// js
new Vue({
el: 'div',
data() {
return {
userInput: ""
}
}
})
We have just appended the trim modifier to the v-model directive.
You can view the example for this code at this link: https://codepen.io/AjdinImsirovic/pen/eKeRXK.
This modifier will trim any whitespace (such as spaces or tabs) typed into the input field by the user.
Before continuing with this 10,000-foot overview of Vue syntax, let's also mention the v-on directive, which is used for event handling. Here is a quick example:
<!-- HTML -->
<div id="example-1">
<button v-on:click="counter += 1">Add 1</button>
<p>The button above has been clicked {{ counter }} times.</p>
</div>
// JS
var example1 = new Vue({
el: '#example-1',
data: {
counter: 0
}
})
Vue even provides shortcut syntax for v-on: the @ symbol. Thus, we can replace v-on:click with just @click and our Vue counter will still work.
To view this example in http://codepen.io/, visit the following URL: https://codepen.io/AjdinImsirovic/pen/PaOjvz.
- 5G承載網(wǎng)網(wǎng)絡(luò)規(guī)劃與組網(wǎng)設(shè)計(jì)
- 物聯(lián)網(wǎng)概論(第2版)
- Learning Karaf Cellar
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 正在爆發(fā)的互聯(lián)網(wǎng)革命
- 電力物聯(lián)網(wǎng)工程技術(shù)原理與應(yīng)用
- Microsoft Dynamics CRM 2011 Applications(MB2-868) Certification Guide
- OMNeT++與網(wǎng)絡(luò)仿真
- 人人都該都懂的互聯(lián)網(wǎng)思維
- 一本書讀懂TCP/IP
- 網(wǎng)絡(luò)安全之道
- 天下一家:網(wǎng)絡(luò)聯(lián)通世界(科學(xué)新導(dǎo)向叢書)
- 移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)
- 計(jì)算機(jī)網(wǎng)絡(luò)技術(shù)實(shí)用寶典(第3版)