Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Weex中使用globalEvent,如何调用methods中的方法?

代码如下:

<script>
var globalEvent = require('@weex-module/globalEvent');
globalEvent.addEventListener("loginStatus", function (e) {
    console.log("loginStatusssa:"+e.loginStatus);
    this.getAnswerListData(1, function(state) {});
});
module.exports = {
    ...省略部分代码...
    
    methods: {
         getAnswerListData: function(pageNo, callBack) {
            var that = this;
            stream.fetch({
                methods: 'GET',
                url: 'xxx',
                type: 'json',
            },function(res) {
            
            })
        },
    }
}
</script>

具体代码就是上面这样,其中globalEvent中的this.getAnswerListData,这个似乎不能用this来调用,该如何嗲用methods中的方法呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
126 views
Welcome To Ask or Share your Answers For Others

1 Answer

在mounted中写:

mounted: function () {
  var self = this;
  globalEvent.addEventListener('loginStatus', function (e) {
    self.getAnswerListData(1, function(state) {});
  });
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...