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

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.

主站蜘蛛池模板: 朝阳市| 濮阳县| 霍林郭勒市| 怀仁县| 依兰县| 镇平县| 安西县| 沅陵县| 迁安市| 安多县| 临洮县| 安阳县| 隆回县| 阳原县| 德保县| 临沂市| 阳朔县| 白山市| 南安市| 商城县| 菏泽市| 罗平县| 普兰店市| 马龙县| 彩票| 城市| 徐汇区| 奉化市| 西贡区| 恩平市| 新郑市| 多伦县| 资阳市| 青海省| 安远县| 抚顺县| 阿合奇县| 普格县| 美姑县| 广昌县| 承德市|