VUE小实例
## Html代码```
Title
<div id="app">
<div>
<table><tr><th></th>
<th>书籍名称</th>
<th>出版日期</th>
<th>价格</th>
<th>购买数量</th>
<th>操作</th>
</tr><tr><td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.date}}</td>
<td>{{item.price | showPrice}}</td>
<td>
-
{{item.count}}
+
</td>
<td>
移除
</td>
</tr></table><h2>总价格:{{totalPrice}}</h2>
</div>
<div>
<h2>购物车为空!</h2>
</div>
</div>
```
## JS代码
```
const app = new Vue({
el: '#app',
data:{
Books:[
{id:1,name:'计算机原理',date:'2015-6',price:50,count:1},
{id:2,name:'认识Python',date:'2016-1',price:100,count:1},
{id:3,name:'你好,易语言',date:'2015-9',price:200,count:1},
{id:4,name:'你好,Vue',date:'2013-6',price:100,count:1},
{id:5,name:'认识Javascprit',date:'2020-6',price:50,count:1},
]
},
methods:{
increment(index){
this.Books.count++
},
decrement(index){
this.Books.count--
},
removeHandle(index){
this.Books.splice(index,1)
}
},
computed:{
totalPrice(){
let totalPrice=0
for (let i = 0 ;i css怎么不见了
table{
border: 1px solid #e9e9e9;
border-collapse: collapse;
border-spacing: 0;
}
th,td{
padding: 8px 16px;
border: 1px solid #e9e9e9;
text-align: left;
}
th{
background-color: #f7f7f7;
color: #5c6b77;
font-weight: 600;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="app">
<div v-if="Books.length">
<table>
<thead>
<tr>
<th></th>
<th>书籍名称</th>
<th>出版日期</th>
<th>价格</th>
<th>购买数量</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="(item,index) in Books">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.date}}</td>
<td>{{item.price | showPrice}}</td>
<td>
<button @click="decrement(index)" :disabled="item.count<=1">-</button>
{{item.count}}
<button @click="increment(index)">+</button>
</td>
<td>
<button @click="removeHandle(index)">移除</button>
</td>
</tr>
</tbody>
</table>
<h2>总价格:{{totalPrice}}</h2>
</div>
<div v-else>
<h2>购物车为空!</h2>
</div>
</div>
<script src="../JS/vue.js"></script>
<script src="main.js"></script>
</body>
</html> const app = new Vue({
el: '#app',
data:{
Books:[
{id:1,name:'计算机原理',date:'2015-6',price:50,count:1},
{id:2,name:'认识Python',date:'2016-1',price:100,count:1},
{id:3,name:'你好,易语言',date:'2015-9',price:200,count:1},
{id:4,name:'你好,Vue',date:'2013-6',price:100,count:1},
{id:5,name:'认识Javascprit',date:'2020-6',price:50,count:1},
]
},
methods:{
increment(index){
this.Books.count++
},
decrement(index){
this.Books.count--
},
removeHandle(index){
this.Books.splice(index,1)
}
},
computed:{
totalPrice(){
let totalPrice=0
for (let i = 0 ;i<this.Books.length;i++)
{
totalPrice += this.Books.price*this.Books.count
}
return totalPrice
},
},
filters:{
showPrice(price){
return"¥" + price.toFixed(2)
},
}
}) 可能有些代码会被检测过滤掉,下次看看有没有什么办法解决... 王一之 发表于 2021-3-10 09:41
可能有些代码会被检测过滤掉,下次看看有没有什么办法解决...
行 哥哥 小陈 发表于 2021-3-10 09:46
行 哥哥
现在的markdown编辑器太拉跨了...后面可能自己开发....心疼购买钱 王一之 发表于 2021-3-10 09:54
现在的markdown编辑器太拉跨了...后面可能自己开发....心疼购买钱
哥哥直接用其他论坛的那种编辑器 方便省事 啧啧 小陈 发表于 2021-3-10 09:57
哥哥直接用其他论坛的那种编辑器 方便省事 啧啧
啥意思,什么编辑器? 王一之 发表于 2021-3-10 10:01
啥意思,什么编辑器?
就其他论坛用的那个好像是自带的还是啥?好像用的都是那个再在上面添加修改点东西 他们
页:
[1]
2