v-model的基本使用
- v-model三种常见的修饰符默认是string
- number的修饰符主要是将string转化成number类型
- trim修饰符主要是去除内容前后的空格仅截取部分核心代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16<template>
<input type="text" v-model.trim="message">
// <input type="text" v-model.number="message">
<h2>{{message}}</h2>
<button @click="showType()">查看类型</button>
<button @click="showCon()">查看内容</button>
</template>
methods: {
showType() {
console.log(this.message, typeof this.message);
},
showCon() {
console.log(this.message);
}
}
EX:
217498daowh 值为217498 类型为number
njdkhaw3431 值为njdkhaw3431 类型为string