当前位置:网站首页>v-model原理及修饰符
v-model原理及修饰符
2022-07-17 00:06:00 【静止呀】
1.原理
<div id="app">
// v-model相当于两个指令的集合(v-bind,v-on)
// input事件:用于监听用户是否输入了东西
<input type="text" :value="message" @input="valueChange">
<input type="text" :value="message" @input="message = $event.target.value">
// 在页面控制台改变该值,data内的数据不会发生改变
{
{
message}}
</div>
<script>
const app = new Vue({
el: '#app',
data: {
message: '你好呀'
},
methods: {
valueChange(event) {
console.log("......")
// 获取输入内容
this.message = event.target.value
}
}
})
</script>
2.修饰符
// 1.lazy修饰符的作用:由于v-model双向绑定,变化地太频繁。添加lazy后,便可以在用户输入完成回车后,数据再进行改变
<input type="text" v-model.lazy="message">
// 2.number修饰符的作用
<input type="number" v-model.number="age">
// typeof总是会显示string类型,因为v-model默认绑定string类型
// 所以改成上面v-model.number就可以了
<h2>{
{
age}}——{
{
typeof age}}</h2>
// 3.trim修饰符的使用,不允许输入空格,字符串左右两边的空格,中间可以有空格
<input type="number" v-model.trim="age">
边栏推荐
猜你喜欢

js截取字符串前几位或者截取字符串后几位

Use bat to automatically execute CMD commands (multiple commands or a single command)

uni-app微信小程序——商城(6)——我的主页

Win10 vscode 代码格式化设置与远程断点调试
![[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]](/img/73/af7ca3f670ffee18081b9ca6a9ccf6.png)
[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]

鼠标右键菜单添加快速打开选项遇见的错误:
![Understand PHP from [Fifth space 2021] easycleanup_ session](/img/fc/95332d488dd6096f3a3f6a9fb11644.png)
Understand PHP from [Fifth space 2021] easycleanup_ session

elemtnui 表格如何修改某行文字颜色(elemtnui table 修改某行文字颜色)

Codeforces round #664C
![[GFCTF 2021]Baby_ Cve-2021-41773 on the web](/img/e0/7541860509b3b77f758447e377f2f7.png)
[GFCTF 2021]Baby_ Cve-2021-41773 on the web
随机推荐
Vue project deployment, cleaning cache
Quine injection of SQL injection
NodeJS 跨域 CORS
网站被黑,通过百度/搜狗等搜索关键词访问跳转到其他网站怎么办?
C Programming Language (2nd Edition)--读书笔记--1.5.2
VsCode建立非工程目录下的头文件自动查找
object-fit:cover;在小程序中不起作用,小程序图片变形了如何处理
Page layout - three column layout solution
二分法查找
uni-app微信公众号(4)——地址管理页面
Uni app wechat applet - Mall (3) - Mall Homepage
uniapp调用地图,进行位置查询,标记定位
The C Programming Language (2nd)--笔记--1.6
From catf1ag two-hour AK match pwn/attack killing, summarize the common command guide of emergency response
Summary of XML external entity injection (xxE target recurrence)
The C Programming Language 2nd --笔记--6.7
uni canvas截取图片
Express的使用方法,路由的匹配与使用
Uni app wechat applet - Mall (7) - Product Details
MoveIt2——2.MoveIt在RViz中的快速入门