VUE框架监听属性

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="vue3.js"></script>
<style>
.pass{
outline-color: green;
}
.fail{
outline-color: red;
}
</style>

</head>
<body>

<div id="app">
<p>{{num}}</p>
<p><input type="text" v-model="num"></p>

<p>
<input type="password" :class="tips" v-model="password">
</p>

</div>

<script>

// 数据驱动界面
var vm = Vue.createApp({
data(){
return {
num:100,
password:"",
tips:"fail"

}
},
methods: {

},
computed:{},
watch:{
num:function (newVal,oldVal) {
// 监听numoldVal
console.log("oldVal",oldVal);
// 监听numneWVal
console.log("newVal",newVal);
},
password:function (newVal,oldVal) {
if(newVal.length>5){
// 边框样式变成绿色
console.log("OK");
this.tips = "pass"
}else{
// 边框样式变成红色
console.log("not OK")
}
}
}
}).mount("#app")

</script>

</body>
</html>

 

 






posted @ 2022-06-14 22:10  呼长喜  阅读(29)  评论(0编辑  收藏  举报