javascript - Problem with asynchronous return value in js?
大家讲道理
大家讲道理 2017-05-19 10:15:01
0
2
407

1. The following is the list rendering of my v-for

 <p class="swiper-slide" v-for="bind in binds">
            <p class="bind_box">
              <p class="bind_box_top">
                <p class="bind_box_face"><img :src="bind.face" v-if="bind.face"><img src="../page/baby/images/face_default.png" v-else></p>
                <p class="bind_box_name">{{bind.name}}</p>
              </p>
              <p class="bind_box_main">
                <p class="bind_box_pic"><img :src="bind.id | createdEwm(bind.name,bind.token)"></p>
                <p class="bind_box_text">扫描二维码关注宝贝</p>
              </p>
            </p>
        </p>

2. The following is the method of createdEwm:

createdEwm:function(id,name,token){
        var ewmUrl="bind|"+id+"|"+name//+"|"+token
        var ewmPath=''
        jsbridge.callMethod({
          methodName:"qrGenerate",
          params:{url:ewmUrl,size:150},
          complete:function(data){
            let obj = JSON.parse(data);
            if(obj.errCode=='0'){
              ewmPath=obj.path
            }else{
                alert(obj.errMsg)
                ewmPath=''
            }
            alert(ewmPath)
            return ewmPath
          }
        })
      }

Question: At this time, alert can pop up the returned ob.path data, but the return returned to: src is empty? Isn't the object returned by return createdEwm? Or is the corresponding return now complete?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
左手右手慢动作

The return of the inner method has nothing to do with the outer method

世界只因有你

You have to see clearly that jsbridgeyi is already executing the callMethod method, and complete is just an aspect under callMethod. If you return ewmPath, this scope is only under callMethod, not under createdEwm, so the return will be empty

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template