<DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue.js</title>
<link rel="stylesheet" href="style2.css">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="vue-app">
<h1>双向数据绑定input/select/textarea</h1>
<label>姓名:</label>
<input type="text" ref="name" v-on:keyup="logName">
<span>{{ name }}</span>
<label>年龄:</label>
<input type="text" ref="age" v-on:keyup="logAge">
<span>{{ age }}</span>
</div>
<script src="app4.js"></script>
</body>
</html>
js:
new Vue({
el:"#vue-app",
data:{
name:"zouzou",
age:30,
},
methods:{
logName: function(){
this.name = this.$refs.name.value;
},
logAge: function(){
this.age = this.$refs.age.value;
}
}
});
或者:
<div id="vue-app">
<h1>双向数据绑定input/select/textarea</h1>
<label>姓名:</label>
<input type="text" v-model="name">
<span>{{ name }}</span>
<label>年龄:</label>
<input type="text" v-model="age">
<span>{{ age }}</span>
</div>
网友评论