index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue.js</title>
<script src="https://unpkg.com/vue@2.5.16/dist/vue.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!--vue-app是根容器-->
<div id="vue-app">
<h1> 双向数据绑定 /input/select/textarea </h1>
<label>姓名:</label>
<input ref="name" type="text" v-on:keyup="logName" v-model="name">
<span>{{ name }}</span>
<label>年龄:</label>
<input ref="age" type="text" v-on:keyup="logAge" v-model="age">
<span>{{ age }}</span>
</div>
<script src="app.js"></script>
</body>
</html>
app.js
new Vue({
el:"#vue-app",
data:{
name:"",
age:""
},
methods:{
logName:function() {
//console.log("你正在输入名字!");
//this.name=this.$refs.name.value;
//console.log(this.$refs.name.value);
},
logAge:function() {
//console.log("你正在输入年龄!");
//this.age=this.$refs.age.value;
}
}
});