index.nvue 2.7 KB
Newer Older
打打卡夫卡's avatar
打打卡夫卡 已提交
1 2
<template>
    <div>
打打卡夫卡's avatar
打打卡夫卡 已提交
3 4 5
        <button @tap="changeUrl">播放本地动画资源</button>
		<button @tap="changeServerUrl">播放远程动画资源</button>
		
打打卡夫卡's avatar
打打卡夫卡 已提交
6 7 8 9 10
        <button @tap="changeAutoPlay">测试AutoPlay</button>
        <button @tap="changeLoop">测试Loop</button>
        <button @tap="changeAction(1)">测试action play</button>
        <button @tap="changeAction(2)">测试action pause</button>
        <button @tap="changeAction(3)">测试action stop</button>
打打卡夫卡's avatar
打打卡夫卡 已提交
11
        <uts-animation-view ref="animView" :path="animUrl" :autoplay="autoplay" :loop="loop" :action="action"
打打卡夫卡's avatar
打打卡夫卡 已提交
12
            :hidden="hidden" @bindended="testAnimEnd" @click="lottieClickTest" @longpress="lottieLongpressTest"
13
            :style="{width:widthNum+'rpx',height:heightNum+'px',background:yanse}">
打打卡夫卡's avatar
打打卡夫卡 已提交
14
        </uts-animation-view>
打打卡夫卡's avatar
打打卡夫卡 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28
        
    </div>
</template>

<script>
  
    export default {
        data() {
            return {
                hidden: false,
                autoplay: false,
                action: "play",
                loop: false,
                yanse: "red",
杜庆泉's avatar
杜庆泉 已提交
29 30
                widthNum: 200,
                heightNum: 500,
打打卡夫卡's avatar
打打卡夫卡 已提交
31
                comShow: true,
32
                animUrl: "/static/anim_a.json"
打打卡夫卡's avatar
打打卡夫卡 已提交
33 34 35 36 37 38 39 40 41
            }
        },
        
        methods: {

            changeAutoPlay: function() {
                this.autoplay = !this.autoplay
            },
            changeUrl: function() {
42 43
                if (this.animUrl == "/static/anim_a.json") {
                    this.animUrl = "/static/anim_b.json"
打打卡夫卡's avatar
打打卡夫卡 已提交
44
                } else {
45
                    this.animUrl = "/static/anim_a.json"
打打卡夫卡's avatar
打打卡夫卡 已提交
46 47 48
                }
            },

打打卡夫卡's avatar
打打卡夫卡 已提交
49 50 51
			changeServerUrl: function() {
                this.animUrl = "https://b.bdstatic.com/miniapp/images/lottie_example_one.json"
            },
打打卡夫卡's avatar
打打卡夫卡 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            changeAction: function(type) {
                if (type == 1) {
                    this.action = "play"
                } else if (type == 2) {
                    this.action = "pause"
                } else if (type == 3) {
                    this.action = "stop"
                }
            },
            changeLoop: function() {
                this.loop = !this.loop
            },
            testAnimEnd: function(res) {
                console.log("testAnimEnd");
                console.log(res);
            },

            changeRepeat: function(res) {
70
                this.$refs["animView"].updateRepeatConfig("RESTART");
打打卡夫卡's avatar
打打卡夫卡 已提交
71 72 73 74 75 76 77 78 79 80 81 82
            },
            lottieClickTest: function(res) {
                console.log("lottieClickTest");
                console.log(res);
            },
            lottieLongpressTest: function(res) {
                console.log("lottieClickTest");
                console.log(res);
            },
        }
    }
</script>