<template>
    <div :style="{width:width+'px',height:height+'px'}">
        <web :style="{width:width+'px',height:height+'px'}" @pagefinish="onPageFinish" :src="src" ref="webview"></web>
    </div>
</template>

<script>
    let fin = [];
    export default {
        props: {
            width: [Number,String],
            height: [Number,String],
            src: String
        },
        methods:{
            draw(cmmand){
                var that = this;
                fin.push(function () {
                    if(process.env.RUNTIME==="native"){
                        var webview = weex.requireModule('webview');
                        that.$nextTick(function(){
                            webview.loadScript(that.$refs.webview,cmmand);
                        })
                    }else{
                        if(that.$refs.webview&&that.$refs.webview.$el) {
                            that.$refs.webview.$el.contentWindow.postMessage(cmmand,'*')
                        }
                    }
                })
            },
            onPageFinish(){
                var that = this;
                fin.forEach(function (f) {
                    f.call(that)
                })
            }
        }
    }
</script>
