Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Vue.createApp({
del: localStorage.delActive ? localStorage.delActive : false,
label: '',
item: '',
items: []
items: [],
histories: []
}
},
watch: {
Expand All @@ -24,14 +25,17 @@ Vue.createApp({
},
methods: {
addItem () {
this.item = eval(this.item.replace(/[^-()\d/*+.]/g, '')) //parse the math expression, but sanitize it
let item = this.item.replace(/[^-()\d/*+.]/g, '') //parse the math expression, but sanitize it
this.item = eval(item)
if (!isNaN(this.item) && this.item!=0) {
this.items.unshift(this.item * 1) //or push - whatever works for you
this.histories.unshift(item)
}
this.item = ''
},
removeItem (n) {
this.items.splice(n, 1)
this.histories.splice(n, 1)
},
undoAddition () {
if (this.del) {
Expand Down
7 changes: 7 additions & 0 deletions assets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,16 @@ ul.items li {
margin-bottom: 1px;
font-size: 22px;
display: grid;
}

.grid-col-2 {
grid-template-columns: 1fr 1fr;
}

.grid-col-3 {
grid-template-columns: 1fr 1fr 1fr;
}

ul.items li.seperator {
height: 1px;
background-color: #ccc;
Expand Down
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
</div>
<div @click="focus">
<ul class="items">
<li v-for="(item,index) in items">
<li v-for="(item,index) in items" class="grid-col-3">
<div class="left">{{item}}</div>
<div>{{ histories[index] }}</div>
<div class="right">
<button @click="removeItem(index)">Delete</button>
</div>
</li>
<!-- <li class="seperator"></li> -->
<li class="total" v-show="sum">
<li class="total grid-col-2" v-show="sum">
<div class="left">Total</div>
<div class="right">{{sum}}</div>
</li>
Expand Down