alibaba / weex

A framework for building Mobile cross-platform UI
https://weexapp.com/
Apache License 2.0
18.28k stars 2.13k forks source link

关于集成到web出现严重的bug(附代码) #1757

Closed MARCUSW10 closed 8 years ago

MARCUSW10 commented 8 years ago

我是按照http://www.jianshu.com/p/5d914fbac9ac将we集成到web的,但是打开localhost:8080出现了Cannot GET /undefined,本来想上传图片的,可是好像上传不了 1 代码是: <template> <wxc-item style="border-width:15px;border-color:#63B8FF;" > <div style="height:1160px;"> <div style="flex-direction:row;width:900px;height:600px;margin-top:100;" > <a> <image style="width:300px;height:300px;margin-top:50px;margin-left:25px;" src="{{List[num1].Photo}}" score="{{List[num1].score}}" onclick="clicked1" > </a> <text style="font-size:50px;left:13px;top:150px;">or <a> <image style="width:300px;height:300px;margin-top:50px;margin-left:30px;" src="{{List[num2].Photo}}" score="{{List[num2].score}}" onclick="clicked2" > </a> </div> </div> </wxc-item> </template> <script> require('weex-components'); module.exports={ data:{ num1:0, num2:5, count:0, List: [ { id: 1, score:1000, canteen:1, Photo: 'https://gd2.alicdn.com/bao/uploaded/i2/TB1rtOnHpXXXXXLaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'2', areaname:'', rank:'', }, { id: 2, score:1000, canteen:1, Photo: 'https://gd2.alicdn.com/bao/uploaded/i2/TB1rtOnHpXXXXXLaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'3', areaname:'', nosize:70, rank:'', }, { id: 3, canteen:1, score:1000, Photo: 'https://gd2.alicdn.com/bao/uploaded/i2/TB1rtOnHpXXXXXLaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'4', areaname:'', nosize:70, rank:'', }, { id: 4, canteen:1, score:1000, Photo: 'https://gd2.alicdn.com/bao/uploaded/i2/TB1rtOnHpXXXXXLaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'4', areaname:'', nosize:70, rank:'', }, { id: 5, canteen:1, score:1000, Photo: 'https://gd4.alicdn.com/bao/uploaded/i4/TB15KrfFVXXXXXJXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'4', areaname:'', nosize:70, rank:'', }, { id: 6, canteen:1, rank:0, score:1000, Photo: 'https://gd4.alicdn.com/bao/uploaded/i4/TB15KrfFVXXXXXJXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'4', areaname:'', nosize:70, rank:'', }, { id: 7, canteen:3, score:1000, Photo: 'https://gd4.alicdn.com/bao/uploaded/i4/TB15KrfFVXXXXXJXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'16', areaname:'', nosize:70, rank:'', }, { id: 8, canteen:3, score:1000, Photo: 'https://gd4.alicdn.com/bao/uploaded/i4/TB15KrfFVXXXXXJXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'13', areaname:'', nosize:70, rank:'', }, { id: 9, canteen:3, score:1000, Photo: 'https://gd2.alicdn.com/bao/uploaded/i2/TB1rtOnHpXXXXXLaXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', name:'', price:'0', areaname:'', nosize:70, rank:'', }, { id: 10, canteen:2, score:1000, Photo: 'https://gd4.alicdn.com/bao/uploaded/i4/TB15KrfFVXXXXXJXXXXXXXXXXXX_!!0-item_pic.jpg_220x220.jpg', rank:'', }, ]
}, methods:{ clicked1:function(){ var n=this.List[this.num2].score-this.List[this.num1].score; var ea=1/(1+10n/400); var eb=1/(1-10n/400); this.List[this.num1].score=this.List[this.num1].score+32(1-ea); this.List[this.num2].score=this.List[this.num2].score+32(0-eb);

          var rand=Math.random()*10;
          rand=Math.floor(rand);
          while(rand==this.num1){
                rand=Math.random()*10;
                rand=Math.floor(rand);
          }
          this.num2=rand;
          this.count++;
          if(this.count==20){
                this.flag2=false;
                this.flag3=true;
                this.flag4=true;
                for(var i=0;i<10;i++){
                    for(var j=i+1;j<10;j++){
                        if(this.List[i].score<this.List[j].score){
                            var temp=this.List[i]
                            this.List[i]=this.List[j]
                            this.List[j]=temp
                            var t=this.List[i].id
                            this.List[i].id=this.List[j].id
                            this.List[j].id=t   
                        }
                    }
                }
                for(var i=0;i<10;i++){
                    switch(this.List[i].id)
                                {
                                  case 1:
                                     this.List[i].rank=this.rank1
                                     break;
                                  case 2:
                                     this.List[i].rank=this.rank2
                                     break;
                                  case 3:
                                     this.List[i].rank=this.rank3
                                     break;
                                  default:
                                     this.List[i].rank=''
                                     break;
                                }
                }   
          }
        },
        clicked2:function(){
           var n=this.List[this.num2].score-this.List[this.num1].score;
           var ea=1/(1+10*n/400);
           var eb=1/(1-10*n/400);
           this.List[this.num1].score=this.List[this.num1].score+32*(0-ea);
           this.List[this.num2].score=this.List[this.num2].score+32*(1-eb);

          var rand=Math.random()*10;
          rand=Math.floor(rand);
          while(rand==this.num2){
                rand=Math.random()*10;
                rand=Math.floor(rand);
          }
          this.num1=rand;
          this.count++;
          if(this.count==20){
                this.flag2=false;
                this.flag3=true;
                this.flag4=true ;
                for(var i=0;i<10;i++){
                        for(var j=i+1;j<10;j++){
                            if(this.List[i].score<this.List[j].score){
                                var temp=this.List[i]
                                this.List[i]=this.List[j]
                                this.List[j]=temp
                                var t=this.List[i].id
                                this.List[i].id=this.List[j].id
                                this.List[j].id=t
                            }
                        }       
                    }

                for(var i=0;i<10;i++){
                    switch(this.List[i].id)
                                    {
                                      case 1:
                                         this.List[i].rank=this.rank1
                                         break;
                                      case 2:
                                         this.List[i].rank=this.rank2
                                         break;
                                      case 3:
                                         this.List[i].rank=this.rank3
                                         break;
                                      default:
                                         this.List[i].rank=''
                                         break;
                                    }
                }
           }
        }
      }
    }

Hanks10100 commented 8 years ago

试一下 http://localhost:8080 不要带 undefined

MARCUSW10 commented 8 years ago

其实我不是这个意思,我打开时使用http://localhost:8080,但是当我点击图片时(图片有onclick函数),页面转到了http://localhost:8080/undefined,这就是问题所在

Hanks10100 commented 8 years ago

你在 <a> 标签里使用了 <image>,点击图片时触发了链接跳转,但是你没指定 src,所以就跳转到了 undefined

MARCUSW10 commented 8 years ago

谢谢各位高手指点