NativeScript使用Vue获取当前的android上下文?

时间:2018-11-19 19:46:32

标签: nativescript nativescript-vue

我正在尝试使用需要上下文实例化UI对象的本机映射库,如何传递它?

原生函数是android.view.View的扩展,其所需的参数是上下文。

Ref:https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/mapping/view/MapView.html#MapView(android.content.Context)

Example.vue:

<template>
    <Page class="page">
        <StackLayout>
            <Placeholder @creatingView="creatingView"/>
         </StackLayout>
    </Page>
</template>

<script>
    export default {
        methods: {
            creatingView(args){
                //This is where I need the context as a parameter
                const nativeView = new com.esri.arcgisruntime.mapping.view.MapView(this.context);
                args.view = nativeView;                    
            }
        }
    };
</script>

2 个答案:

答案 0 :(得分:0)

无论使用哪种样式/框架,都可以使用以下应用程序上下文

import * as application from "application";

const context = application.android.context;

答案 1 :(得分:0)

您可以从createdView事件args获取当前的android上下文。

methods: {
       creatingView(args){
           const nativeView = new com.esri.arcgisruntime.mapping.view.MapView(args.context);
           args.view = nativeView;                    
       }
}