index.nvue 1.3 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6
<template>
	<div>
		<animation-view class="animation" :path="path" :loop="loop" :autoplay="autoplay" :action="action"
			:hidden="hidden" @bindended="lottieEnd">
		</animation-view>
		<button @click="playLottie" type="primary">{{status}}lottie动画</button>
7
		<button @click="changeLottie" type="primary">切换{{location}}动画</button>
DCloud-yyl's avatar
DCloud-yyl 已提交
8 9 10 11 12 13 14
	</div>
</template>

<script>
	export default {
		data() {
			return {
DCloud-yyl's avatar
DCloud-yyl 已提交
15
				path: '/uni_modules/uni-animation-view/static/lottie.json',
DCloud-yyl's avatar
DCloud-yyl 已提交
16 17
				loop: false,
				autoplay: false,
18
				action: 'stop',
DCloud-yyl's avatar
DCloud-yyl 已提交
19
				hidden: false,
20 21
				status: '播放',
				location: '网络'
DCloud-yyl's avatar
DCloud-yyl 已提交
22 23 24 25 26 27 28
			}
		},
		methods: {
			playLottie() {
				this.action = ('play' !== this.action) ? 'play' : 'pause';
				this.status = ('pause' === this.action) ? '播放' : '暂停';
			},
29 30 31 32 33 34 35
			changeLottie() {
				this.action = 'stop';
				this.status = '播放';
				this.path = ('网络' === this.location) ? 'https://native-res.dcloud.net.cn/uni-app/static/lottie.json' : '/uni_modules/uni-animation-view/static/lottie.json';
				this.location = ('网络' === this.location) ? '本地' : '网络';
				console.log('path='+this.path);
			},
DCloud-yyl's avatar
DCloud-yyl 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48
			lottieEnd() {
				this.status = '播放';
				this.action = 'stop';
				console.log('动画播放结束');
			}
		}
	}
</script>

<style>
	.animation {
		width: 750rpx;
		height: 300rpx;
49
		background-color: #CCCCCC;
DCloud-yyl's avatar
DCloud-yyl 已提交
50 51 52
		margin-bottom: 20px;
	}
</style>