开始学习动画

new_branch1
roger 2 years ago
parent 7b4f8bb7dc
commit d0a9bf874f
  1. 145
      20_脚手架/vue_code/16.src_nextTick/App.vue
  2. BIN
      20_脚手架/vue_code/16.src_nextTick/assets/logo.png
  3. 0
      20_脚手架/vue_code/16.src_nextTick/components/TodoBottom.vue
  4. 0
      20_脚手架/vue_code/16.src_nextTick/components/TodoHeader.vue
  5. 0
      20_脚手架/vue_code/16.src_nextTick/components/TodoItem.vue
  6. 0
      20_脚手架/vue_code/16.src_nextTick/components/TodoList.vue
  7. 19
      20_脚手架/vue_code/16.src_nextTick/main.js
  8. 134
      20_脚手架/vue_code/src/App.vue
  9. 57
      20_脚手架/vue_code/src/components/Test.vue

@ -0,0 +1,145 @@
<template>
<div id="root">
<div class="todo-container">
<div class="todo-wrap">
<TodoHeader @addTodo="addTodo"/>
<TodoList :todos="todos"/>
<TodoBottom :todos="todos" @checkAllTodo="checkAllTodo" @clearAllTodo="clearAllTodo"/>
</div>
</div>
</div>
</template>
<script>
import pubsub from 'pubsub-js'
import TodoHeader from "./components/TodoHeader.vue";
import TodoList from "./components/TodoList.vue";
import TodoBottom from "./components/TodoBottom.vue";
export default {
name: "App",
components: {
TodoHeader,
TodoList,
TodoBottom
},
data() {
return {
//
todos: JSON.parse(localStorage.getItem('todos')) || []
}
},
// 访App
// App
methods: {
// todoTodoHeader
addTodo(todoObj) {
this.todos.unshift(todoObj)
},
// todo穿TodoListTodoItem
checkTodo(id) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.done = !todo.done
})
},
// todo穿TodoListTodoItem
deleteTodo(_, id) {
this.todos = this.todos.filter(todo => todo.id !== id)
},
// TodoItem
updateTodo(id, title) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.title = title
})
},
// todoTodoBottom
checkAllTodo(done) {
this.todos.forEach((todo) => todo.done = done)
},
// todoTodoBottom
clearAllTodo() {
this.todos = this.todos.filter((todo) => {
return !todo.done
})
}
},
watch: {
todos: {
deep: true,
handler(value) {
localStorage.setItem('todos', JSON.stringify(value))
}
}
},
// 线
mounted() {
this.$bus.$on('checkTodo', this.checkTodo)
this.$bus.$on('updateTodo', this.updateTodo)
this.pubId = pubsub.subscribe('itemDel', this.deleteTodo) // 使
},
// 线
beforeDestroy() {
this.$bus.$off('checkTodo')
this.$bus.$off('updateTodo')
this.pubsub.unsubscribe(this, pubId) // 使
}
}
</script>
<style>
body {
background: #fff;
}
.btn {
display: inline-block;
padding: 4px 12px;
margin-bottom: 0;
font-size: 14px;
line-height: 20px;
text-align: center;
vertical-align: middle;
cursor: pointer;
box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
border-radius: 4px;
}
.btn-danger {
color: #fff;
background-color: #da4f49;
border: 1px solid #bd362f;
}
.btn-edit {
color: #fff;
background-color: skyblue;
border: 1px solid #82cdea;
margin-right: 5px;
}
.btn-danger:hover {
color: #fff;
background-color: #bd362f;
}
.btn:focus {
outline: none;
}
.todo-container {
width: 600px;
margin: 0 auto;
}
.todo-container .todo-wrap {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

@ -0,0 +1,19 @@
// 引入Vue
import Vue from "vue";
// 引入App
import App from "./App";
// 设置Vue
Vue.config.productionTip = false
// 实例化Vue
new Vue({
components: {
App
},
render: h => h(App),
beforeCreate() {
Vue.prototype.$bus = this // 安装全局事件总线
}
}).$mount('#app')

@ -1,145 +1,19 @@
<template> <template>
<div id="root"> <div>
<div class="todo-container"> <Test/>
<div class="todo-wrap">
<TodoHeader @addTodo="addTodo"/>
<TodoList :todos="todos"/>
<TodoBottom :todos="todos" @checkAllTodo="checkAllTodo" @clearAllTodo="clearAllTodo"/>
</div>
</div>
</div> </div>
</template> </template>
<script> <script>
import pubsub from 'pubsub-js' import Test from "./components/Test.vue"
import TodoHeader from "./components/TodoHeader.vue";
import TodoList from "./components/TodoList.vue";
import TodoBottom from "./components/TodoBottom.vue";
export default { export default {
name: "App", name: "App",
components: { components: {
TodoHeader, Test
TodoList,
TodoBottom
},
data() {
return {
//
todos: JSON.parse(localStorage.getItem('todos')) || []
}
},
// 访App
// App
methods: {
// todoTodoHeader
addTodo(todoObj) {
this.todos.unshift(todoObj)
},
// todo穿TodoListTodoItem
checkTodo(id) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.done = !todo.done
})
},
// todo穿TodoListTodoItem
deleteTodo(_, id) {
this.todos = this.todos.filter(todo => todo.id !== id)
},
// TodoItem
updateTodo(id, title) {
this.todos.forEach((todo) => {
if (todo.id === id) todo.title = title
})
},
// todoTodoBottom
checkAllTodo(done) {
this.todos.forEach((todo) => todo.done = done)
},
// todoTodoBottom
clearAllTodo() {
this.todos = this.todos.filter((todo) => {
return !todo.done
})
}
},
watch: {
todos: {
deep: true,
handler(value) {
localStorage.setItem('todos', JSON.stringify(value))
}
}
}, },
// 线
mounted() {
this.$bus.$on('checkTodo', this.checkTodo)
this.$bus.$on('updateTodo', this.updateTodo)
this.pubId = pubsub.subscribe('itemDel', this.deleteTodo) // 使
},
// 线
beforeDestroy() {
this.$bus.$off('checkTodo')
this.$bus.$off('updateTodo')
this.pubsub.unsubscribe(this, pubId) // 使
}
} }
</script> </script>
<style> <style>
body {
background: #fff;
}
.btn {
display: inline-block;
padding: 4px 12px;
margin-bottom: 0;
font-size: 14px;
line-height: 20px;
text-align: center;
vertical-align: middle;
cursor: pointer;
box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
border-radius: 4px;
}
.btn-danger {
color: #fff;
background-color: #da4f49;
border: 1px solid #bd362f;
}
.btn-edit {
color: #fff;
background-color: skyblue;
border: 1px solid #82cdea;
margin-right: 5px;
}
.btn-danger:hover {
color: #fff;
background-color: #bd362f;
}
.btn:focus {
outline: none;
}
.todo-container {
width: 600px;
margin: 0 auto;
}
.todo-container .todo-wrap {
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
</style> </style>

@ -0,0 +1,57 @@
<template>
<div>
<button @click="isShow=!isShow">显示/隐藏</button>
<!-- Vue默认实现动画方式 -->
<!-- :appear="true" -->
<transition appear>
<h1 v-show="isShow" class="come">你好啊</h1>
</transition>
<!-- 自定义名称实现动画 -->
<transition name="hello">
<h1 v-show="isShow" class="come">你好啊</h1>
</transition>
</div>
</template>
<script>
export default {
name: "Test",
data() {
return {
isShow: true
}
}
}
</script>
<style scoped>
h1 {
background-color: orange;
width: 300px;
}
/*Vue默认实现动画方式*/
.v-enter-active{
animation: demo 0.5s linear;
}
.v-leave-active{
animation: demo 0.5s linear reverse;
}
/*自定义名称实现动画*/
.hello-enter-active{
animation: demo 0.5s linear;
}
.hello-leave-active{
animation: demo 0.5s linear reverse;
}
@keyframes demo {
from{
transform: translateX(-100%);
}
to{
transform: translateX(0px);
}
}
</style>
Loading…
Cancel
Save