vue 단순 카 트 사례 실현
코드:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div id="app">
<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' ::key="item">
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.date}}</td>
<td>{{item.price*item.count | getFinalPrice}}</td>
<td>
<button @click='reduce(index)' :disabled='item.count <= 1'>-</button>
{{item.count}}
<button @click='add(index)'>+</button>
</td>
<td>
<button @click='removeBtn(index)'> </button>
</td>
</tr>
</tbody>
</table>
<h2 v-if='books!=""'> :{{theSumOf | getFinalPrice}}</h2>
<h2 v-else> </h2>
</div>
</body>
<script src="../js/vue.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data: {
books: [
{
id: 1,
name: ' ',
date: '2006-9',
price: 85.00,
count: 1
},
{
id: 2,
name: 'java ',
date: '2006-9',
price: 10.00,
count: 1
},
{
id: 3,
name: ' ',
date: '2006-9',
price: 85.00,
count: 1
},
{
id: 4,
name: 'ui ',
date: '2006-9',
price: 85.00,
count: 1
},
],
addAnd:0
},
methods: {
add(index) {
this.books[index].count++
},
reduce(index) {
this.books[index].count--
},
removeBtn(index) {
this.books.splice(index, 1)
}
},
components: {
},
computed: {
theSumOf: function () {
//
//let sum = 0
//this.books.forEach(item => {
// sum += parseInt(item.price)*parseInt(item.count)
});
//return sum
//
//let sum = 0
//for(let i in this.books){
//sum += this.books[i].price*this.books[i]*count
}
//return sum
//
//let sum = 0
//for(let item of this.books){
//sum += item.price*item.count
//}
//return sum
//
return this.books.reduce(function(preValue,book){
return preValue + book.price*book.count
},0)
}
},
filters: {
getFinalPrice(price) {
return '¥' + price.toFixed(2)
},
}
});
</script>
<html>
vue.js 의 학습 튜 토리 얼 에 대해 서 는 주제vue.js 구성 요소 학습 강좌,Vue.js 전단 구성 요소 학습 튜 토리 얼를 클릭 하여 공부 하 십시오.이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Fastapi websocket 및 vue 3(Composition API)1부: FastAPI virtualenv 만들기(선택 사항) FastAPI 및 필요한 모든 것을 다음과 같이 설치하십시오. 생성main.py 파일 및 실행 - 브라우저에서 이 링크 열기http://127.0.0.1:...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.