首页 > 其他 > 详细

表单和侦听器

时间:2019-08-06 02:44:44      阅读:108      评论:0      收藏:0      [点我收藏+]

表单输入绑定

修饰符:

.lazy

.number

.trim

watch:监听数据变化

计算属性vs监听属性

能用计算属性的,一般都用计算属性,实在不行才用监听属性;

<template>
<div :class="classdemo">sdfsfs
<form action="">
<input type="text" value="1232222" v-model="msgtexts" placeholder="请输入手机号">
<p>{{msgtexts}}</p>
<input type="checkbox" id="checkbox" v-model="checked">
<label for="checkbox">{{checked}}</label>
<!-- 懒惰-->
<input type="text" id="" v-model.lazy="msgstxts">
<p>{{msgstxts}}</p>
<!-- number-->
<input type="text" id="" v-model.number="tels">
<p>{{tels}}</p>
<!-- trim-->
<input type="text" id="" v-model.trim="msg">
<p>{{msg}}</p>
<button class="" @click="ageadd">改变按钮来改变p的内容</button>
<p>{{myage}}</p>
</form>
</div>
</template>

<script>
export default {
name: "forma",
data() {
return {
classdemo: "active",
actives: true,
currents: "current",
classobj: {
"text1": true,
"text2": true
},
activeClass: "active1",
currentIndex: "currents",
currentIndex1: "curr",
isActive: true,
colors:"yellow",
msgtexts:"默认值",
checked:false,
msgstxts:"text",
tels:"",
msg:"12345",
myage:10
}
},
methods: {
changecss() {
this.classobj = {
"text1": true,
"text2": false
}
},
ageadd(){
this.myage++;
}
},
watch:{
msgstxts(data){
if(data=="10"){
console.log("10000");
this.msgstxts="输入正确"
}else{

}
},
myage(data){
console.log(data)
}
}
}
</script>
<style scoped>
.active1 {
color: red;
}
.currents {
color: blue;
}
</style>

表单和侦听器

原文:https://www.cnblogs.com/xiao-peng-ji/p/11306337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!