逛水果店:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.base{
text-align: center;
}
.tab{
display: inline-block;
}
.tab table{
width: 500px;
height: 50px;
}
</style>
</head>
<body>
<div class="base" id="app">
<p>欢迎光临vue开发的收银系统_水果店</p>
<div class="tab">
<table border="1">
<tr>
<th>苹果10¥/斤,折扣 <8折></th>
</tr>
<tr>
<td>请输入你要购买的斤数<input type="text" v-model.number="a"></td>
</tr>
<tr>
<td><button @click="sum()">结账买单</button></td>
</tr>
<tr>
<td>结账单:总价:{{this.b}}元 折后价:{{b*0.8}}元 省了:{{b-b*0.8}} 元</td>
</tr>
</table>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
<script>
const app=new Vue({
el:'#app',
data:{
a:'0',
b:'0'
},
methods:{
sum(){
if(typeof this.a =="number"){
this.b=this.a*10
}
else{
alert('请输入合法数字')
}
}
}
})
</script>
</body>
</html>