11.Vue双向数据绑定

it2023-06-17  69

1. 示例代码

<!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>双向数据绑定</title> <script src="./js/vue.js"></script> </head> <body> <div id="app"> <p>{{msg}}</p> <input type="text" :value="msg" @input="msg=$event.target.value"/> <input type="text" v-model="msg"/> </div> </body> <script> new Vue({ el:"#app", data:{ msg:"abc" }, methods:{ cm:function(){ this.msg="test123" } } }); </script> </html>

2. 运行结果

最新回复(0)