3***@qq.com
3***@qq.com
  • 发布:2020-03-09 13:55
  • 更新:2020-03-09 16:39
  • 阅读:802

【报Bug】工具升级到2.6.1之后 挂载 Vue.prototype 出现问题

分类:HBuilderX

我在main.js文件挂载globalData属性
app.vue的时候给赋值,
在界面去取,一直为空;
之前一直是好的,昨天把工具更新以后就不行了。

main.js

import Vue from 'vue'  
import App from './App'  
Vue.config.productionTip = false  

Vue.prototype.staticUrl = "https://localhost:44300/";  
Vue.prototype.globalData = {  
    userInfo: null,  
    openid: null  
};  
App.mpType = 'app'  

const app = new Vue({  
    ...App  
})  
app.$mount()

app.vue 文件

<script>  
    export default {  
        onLaunch: function() {  
            console.log('App Launch');  
            var _self = this;              
            _self.globalData.openid = "1";  
            _self.globalData.userInfo = "332"             
        },  
        onShow: function() {  
            console.log('App Show')  
        },  
        onHide: function() {  
            console.log('App Hide')  
        }  
    }  
</script>

页面代码

onLoad() {  
            var _this = this;  
            var intervalId = setInterval(function() {                  
                console.log(_this.globalData);  
                if (_this.globalData.openid != null && _this.globalData.openid != "") {  
                    clearInterval(intervalId);  
                    console.log(2);  
                    if (_this.globalData.userInfo != null && _this.globalData.userInfo.Id > 0) {  

                    } else {  
                        uni.reLaunch({  
                            url: 'login'  
                        });  
                    }  
                }  
            }, 200);  
        }
2020-03-09 13:55 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

是我迷了,globalData比较特殊,不推荐这种方式

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