添加案例

mac_study
roger 2 years ago
parent ebc6b2c321
commit 5b450a3f80
  1. 39
      08_计算属性/3.姓名案例_计算属性实现.html
  2. 32
      08_计算属性/4.姓名案例_计算属性简写.html

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3.姓名案例_计算属性实现</title>
<script type="text/javascript" src="../vue.js"></script>
</head>
<body>
<div id="root">
姓:<input type="text" v-model="firstName"> <br>
名:<input type="text" v-model="lastName"> <br>
姓名: <span>{{fullName}}</span>
</div>
<script type="text/javascript">
const vm = new Vue({
el: '#root',
data: {
firstName: "张",
lastName: "三"
},
computed: {
fullName: {
get() {
return this.firstName + '-' + this.lastName
},
set(value){
const arr = value.split('-')
this.firstName = arr[0]
this.lastName = arr[1]
}
}
}
})
console.log(vm)
</script>
</body>
</html>

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>4.姓名案例_计算属性简写</title>
<script type="text/javascript" src="../vue.js"></script>
</head>
<body>
<div id="root">
姓:<input type="text" v-model="firstName"> <br>
名:<input type="text" v-model="lastName"> <br>
姓名: <span>{{fullName}}</span>
</div>
<script type="text/javascript">
const vm = new Vue({
el: '#root',
data: {
firstName: "张",
lastName: "三"
},
computed: {
fullName() {
return this.firstName + '-' + this.lastName
}
}
})
console.log(vm)
</script>
</body>
</html>
Loading…
Cancel
Save