案例一:通过插值语法实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>姓名案例_插值语法实现</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 准备一个盒子 -->
<div id="root">
姓: <input type="text" v-model:value="firstName"><br><br>
名: <input type="text" :value="lastName"><br><br>
全名 : <span>{{firstName + '-' + lastName}}</span>
<!-- <span>{{firstName}}-{{lastName}}</span> -->
</div>
</body>
<script text="text/javascript">
Vue.config.producttionTip = false //阻止Vue在启动的时候生成生产提示
new Vue ({
el:'#root',
data:{
firstName:'张',
lastName:'三'
}
})
</script>
</html>
案例二:通过methods实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>姓名案例_methdos实现</title>
<script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<!-- 准备一个盒子 -->
<div id="root">
姓: <input type="text" v-model:value="firstName"><br><br>
名: <input type="text" :value="lastName"><br><br>
全名 : <span>{{fullName()}}</span>
<!-- <span>{{firstName}}-{{lastName}}</span> -->
<!-- <span>{{firstName + '-' + lastName}}</span> -->
<!-- <button @click="fullName">点就死</button> -->
</div>
</body>
<script text="text/javascript">
Vue.config.producttionTip = false //阻止Vue在启动的时候生成生产提示
new Vue ({
el:'#root',
data:{
firstName:'张',
lastName:'三'
},
methods:{
fullName(){
return this.firstName +'-'+this.lastName
}
},
})
</script>
</html>