index.nvue 2.9 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 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
        <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>
        <animation-view ref="animView" :path="animUrl" :autoplay="autoplay" :loop="loop" :action="action"
            :hidden="hidden" @bindended="testAnimEnd" @click="lottieClickTest" @longpress="lottieLongpressTest"
            :style="{width:widthNum+'px',height:heightNum+'px',background:yanse}">
        </animation-view>
        
    </div>
</template>

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

            changeAutoPlay: function() {
                this.autoplay = !this.autoplay
            },
            changeUrl: function() {
打打卡夫卡's avatar
打打卡夫卡 已提交
42 43
                if (this.animUrl == "anim_a.json") {
                    this.animUrl = "anim_b.json"
打打卡夫卡's avatar
打打卡夫卡 已提交
44
                } else {
打打卡夫卡's avatar
打打卡夫卡 已提交
45
                    this.animUrl = "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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
            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) {
                let repeatConfig = {
                    count: 3,
                    mode: "restart"
                }
                console.log(this.$refs["animView"]);
                this.$refs["animView"].updateRepeatConfig(repeatConfig, function(res) {
                    console.log(res);
                });

            },
            lottieClickTest: function(res) {
                console.log("lottieClickTest");
                console.log(res);
            },
            lottieLongpressTest: function(res) {
                console.log("lottieClickTest");
                console.log(res);
            },
        }
    }
</script>