j***@163.com
j***@163.com
  • 发布:2020-08-10 11:59
  • 更新:2020-08-10 11:59
  • 阅读:744

有偿求助,evaljs函数在ios13不执行的问题

分类:uni-app

在uniapp里用webview打开本地网页,然后用如下代码传入token在本地网页请求api,在安卓端运行正常,在ios端无法获取token。求大神帮忙解决
vue页面代码:

methods: {  
        async init(e) {  
            this.src = `/hybrid/html/kline.html?title=${e.title}&no=${e.no}&alias=${e.alias}`;  
            this.is_set = true;  
        },  
        // 跳转  
        async go_url(...e) {  
            this.$tools.url(e[0], e[1]);  
        }  
    },  
    onLoad(e) {  
        this.init(e);  
    },  
    onReady() {  
        // #ifdef APP-PLUS  
        let currentWebview = this.$scope.$getAppWebview(); //获取当前页面的webview对象  
        this.web = currentWebview.children()[0];  
        this.web.evalJS(`env.token='${this.$store.state.token}'`);  
        // #endif  
    }  
};

html页面代码:

//token获取  
    <script>  
        var env = {  
            h5: '',  
            plus: '',  
            token: '',  
            mode: '',  
            wallet: '',  
            wallet_cur: '',  
            dates: [],  
            dataMinutes: [],  
            volumes: [],  
            socket: '',  
            alias: '',  
        }  
        document.addEventListener('UniAppJSBridgeReady', function() {  
            uni.getEnv(function(res) {  
                env.h5 = res.h5  
                env.plus = res.plus  
                console.log('当前环境:' + JSON.stringify(res));  
            });  

            if (env.h5) {  
                env.token = localStorage.token  
            }  

            if (env.plus) {  
                // postMessage(123)  
            }  
// 接口配置  
            fly.config.headers = {  
                Authorization: `bearer ${env.token}`  
            }  
            fly.config.baseURL = "http://client.xxxxx.com/api/"  

            fly.request('user/info', {}, {  
                method: 'post',  
            }).then(e => {  
                e = e.data  
                let data = e.data  
                let info = e.info  
                let status = e.status  

                if (env.wallet == 2) {  
                    env.wallet_cur = data.compute  
                } else if (env.wallet == 3) {  
                    env.wallet_cur = data.trade  
                } else {  
                    env.wallet_cur = 0  
                }  

            }).catch(e => {  
                console.log(e);  
                alert(e)  
            })  
2020-08-10 11:59 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复