-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
michael
committed
Nov 5, 2019
1 parent
0050f7f
commit 5bdbccb
Showing
2 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<div> | ||
<input type="text" name="a1" id="a1" v-model="text" style="margin-right:1rem;" /> | ||
<input @click="appendClick" type="button" class="btn btn-primary" value="新增" /> | ||
<transition-group tag="ul" name="slide"> | ||
<li v-for="item in testList" :key="item.id">{{item.id}} - {{item.title}}</li> | ||
</transition-group> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
// 這裡要完成一個 group transition 把資料加到 ul 內 | ||
data() { | ||
return { | ||
text: "", | ||
testList: [] | ||
}; | ||
}, | ||
methods: { | ||
appendClick() { | ||
const vm = this; | ||
if (vm.text.trim() !== "") { | ||
const maxid = vm.testList.reduce( | ||
(prev, curr) => { | ||
const max = Math.max(Number(prev.id), Number(curr.id)) + 1; | ||
return { id: max }; | ||
}, | ||
{ | ||
id: 1 | ||
} | ||
).id; | ||
vm.testList.push({ | ||
id: maxid, | ||
title: vm.text | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
// 這個時候可以考慮用 transition-group | ||
// OK 完成了!,如果要 transition-group | ||
// 要用 tag 去處理。把物件變為可以用的 | ||
// 當出現和消失的狀態可以用的時候可以考慮用 transition-group | ||
.slide-enter { | ||
opacity: 0; | ||
transform:translateY(10px); | ||
} | ||
.silde-leave-active, | ||
.slide-enter-active { | ||
transition: all 0.5s ease-out; | ||
} | ||
.silder-leave-to { | ||
opacity: 0; | ||
transform:translateY(-10px); | ||
} | ||
</style> |