<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div id="app">
<!-- 用户名是3-6位 -->
<input type="text" placeholder="请输入用户名" v-model="username"><span>{{tips}}</span>
</div>
<script src="vue.js"></script>
<script>
const vm = new Vue({
el: '#app',
data: {
username: '',
tips: ''
},
watch: {
username(value) {
if (value.length >= 3 && value.length <= 6) {
this.tips = '✔'
}else {
this.tips = '✖'
}
}
}
})
</script>
</body>
</html>
vue中的侦听器-监听的小demo
最新推荐文章于 2024-11-07 13:38:59 发布