Y***@sina.com
Y***@sina.com
  • 发布:2024-12-23 16:58
  • 更新:2024-12-24 15:19
  • 阅读:107

uniapp在android真机运行时,uni.getStorageSync is not a function

分类:uni-app

我在页面中使用了uni.getStorageSync方法,在web运行是正常的,但是运行在真机上时,会报方法找不到的错误。
是一个地图功能,script用了renderjs,引用了自定义的一个mapTool的js文件,js中有init方法,在init方法中使用了getStorageSync方法。

2024-12-23 16:58 负责人:DCloud_UNI_OttoJi 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

提供个单页面源码,说一下 vue 和 HBuilderX 版本

  • 2***@qq.com

    我遇到了同样的问题 vue3 hbuilderx4.36

    2024-12-24 15:17

  • Y***@sina.com (作者)

    vue3,HBuilderX4.36。单页面源码如下

    <template>

    <view style="width: 100%;height: 100vh;">

    <view class="mapview" id="mapView"></view>

    </view>

    </template>


    <script>

    export default {

    data() {

    return {


            }  
    },
    onShow() {
    // this.showMap();
    },
    methods: {
    // showMap() {
    // var that = this;
    // mapTools.init("mapView", () => {
    // //加载完成后调用

    // }, (lat, lon) => {

    // });
    // },
    }
    }

    </script>


    <script module="myMapViews" lang="renderjs">

    // import mapTools from "../../../js_sdk/arcgis_map_tools/mapTools.js";

    export default {

    data() {

    return {}

    },

    mounted() {

    // 页面初始化完成后

    this.showMap();

    },

    methods: {

    showMap() {

    // mapTools.init("mapView", () => {

    // //加载完成后调用


                //      }, (lat, lon) => {  

    // });
    uni.getStorageSync({
    key: "mapService",
    success: function(res) {
    mapService = res.data;
    }
    });
    },
    }
    }

    </script>


    <style>

    .mapview {

    width: 100%;

    height: 100%;

    position: absolute;

    z-index: auto;

    background-color: #eee;

    }

    </style>

    2024-12-24 15:22

2***@qq.com

2***@qq.com

我遇到了同样的问题 vue3 hbuilderx4.36

  • Y***@sina.com (作者)

    好像是renderjs里面无法调用uni的方法。没别的办法的话,只能是在原生uni的script中调用uni方法,数据传给renderjs用

    2024-12-24 15:39

要回复问题请先登录注册