黑马模板网专注企业网站模板制作,包括企业pbootcms网站模板,静态网页模板,网站源码下载,HTML网站模板等等。
免责声明:本站所有资源(模板、图片)搜集整理于互联网或者网友提供,仅供学习与交流使用,如果不小心侵犯到你的权益,请及时联系我们删除该资源。
main.js
//引入Vue
import Vue from "vue";
//引入App
import App from './App';
//关闭Vue的生产提示
Vue.config.productionTip = false;
new Vue({
el: '#app',
render: h => h(App),
beforeCreate() {
//事件总线
Vue.prototype.$bus = this;
}
});
App.vue
<template>
<div id="root">
<Test/>
<Test2/>
<Test3/>
</div>
</template>
<script>
import Test from "@/components/Test";
import Test2 from "@/components/Test2";
import Test3 from "@/components/Test3";
export default {
name: "App",
components:{
Test,
Test2,
Test3
},
}
</script>
Test.vue
<template>
<div>
<button @click="isShow = !isShow">
显示/隐藏
</button>
<transition name="hello" appear>
<h1 v-show="isShow">你好啊!</h1>
</transition>
</div>
</template>
<script>
export default {
name: "Test",
data(){
return {
isShow: true
}
}
}
</script>
<style scoped>
h1{
background: orange;
}
.hello-enter-active{
animation: anim linear 0.5s;
}
.hello-leave-active{
animation: anim linear 0.5s reverse;
}
@keyframes anim {
from {
transform: translateX(-100%);
}
to{
transform: translateX(0px);
}
}
</style>
Test2.vue
<template>
<div>
<button @click="isShow = !isShow">
显示/隐藏
</button>
<!--transition 只能包裹一个元素而transition-group可以包含多个元素-->
<transition-group name="hello" appear>
<h1 v-show="isShow" key="1">你好!</h1>
<h1 v-show="isShow" key="2">Shanghai</h1>
</transition-group>
</div>
</template>
<script>
export default {
name: "Test2",
data(){
return {
isShow: true
}
}
}
</script>
<style scoped>
h1{
background: orange;
}
/*进入的起点,离开的终点*/
.hello-enter,
.hello-leave-to{
transform: translateX(-100%);
}
/*进入的过程,离开的过程*/
.hello-enter-active,
.hello-leave-active{
transition: linear .5s;
}
/*进入的终点,离开的起点*/
.hello-enter-to,
.hello-leave{
transform: translateX(0);
}
</style>
Test3.vue
<template>
<div>
<button @click="isShow = !isShow">
显示/隐藏
</button>
<!--transition 只能包裹一个元素而transition-group可以包含多个元素-->
<transition-group
appear
name="animate__animated animate__bounce"
enter-active-class="animate__swing"
leave-active-class="animate__backOutUp"
>
<h1 v-show="isShow" key="1">你好!</h1>
<h1 v-show="isShow" key="2">Shanghai</h1>
</transition-group>
</div>
</template>
<script>
import 'animate.css';
export default {
name: "Test3",
data(){
return {
isShow: true
}
}
}
</script>
<style scoped>
h1{
background: orange;
}
</style>