vue 双向绑定v-model

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Hello Vue</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        /* 刷新的时候不显示 */
        [v-cloak]{
            display: none;
        }

        .content{
            width: 300px;height: 300px;background: #ff6a00;margin: 100px auto;
        }
    </style>
</head>
<body>
    <div id="main">
        <h1>{{msg}}</h1>
        <input type="text" v-model="msg" />
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            // 要用哪一个div 即V层
            el : '#main',
            // 数据 即M层
            data : {
                msg:"hello vue"
            },
            // 初始化页面函数
            mounted(){
                
            },
            // 方法 函数
            methods : {
                

                },

            })
    </script>
</body>
</html>

input默认显示msg 

input输入的内容又可以绑定msg变量的数据

51cto:http://edu.51cto.com/center/course/lesson/index?id=290717

猜你喜欢

转载自blog.csdn.net/damei2017/article/details/82788635