侦听器watch,实时更新属性

Original 2018-11-26 10:28:19 191
abstract:<!DOCTYPE html> <html> <head>     <meta charset="UTF-8">     <title>侦听器</title> </head> <body&g
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>侦听器</title>
</head>
<body>
<div id="box">
    用户名:<input type="text" v-model="username"> <br>
    <h3>{{length}}</h3>
    <h3 v-show="isShow" :style="warning">{{message}}</h3>
</div>

<script src="js/vue.js"></script>
<script>
    new Vue({
        el: '#box',
        data: {
            username: '',
            length: 0,
            message: '用户名过短',
            isShow: false,
            warning: 'color:red'
        },
        
        watch: {
            username: function () {
                this.length=this.username.length;
                //console.log(this.username);
                if (this.length < 6) {
                    this.isShow = true;
                } else {
                    this.isShow = false;
                }
            }
        }
    });
</script>
</body>
</html>

侦听器:实时监测页面中数据的变化

实时更新数据模型中的属性,并完成指定的动作

watch中侦听的属性必须是页面中的变量

Correcting teacher:灭绝师太Correction time:2018-11-26 10:32:18
Teacher's summary:学习的进度很快,学习的过程中要确保知识点掌握奥!

Release Notes

Popular Entries