鍍金池/ 問答/HTML/ 微信小程序bug,合法域名這類問題。

微信小程序bug,合法域名這類問題。

app.json:

{
  "pages":[
    "pages/music1/music1",
    "pages/music2/music2",
    "pages/music3/music3",
    "pages/music4/music4",
    
    "pages/logs/logs"
  ],
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "微音樂",
    "navigationBarTextStyle":"black"
  },
  "tabBar": {
    "color": "#818181",
    "backgroundColor": "black",
    "selectedColor": "green",
    "list": [{
      "pagePath": "pages/music1/music1",
      "text": "音樂列表",
      "iconPath": "image/music.jpg",
      "selectedIconPath": "/image/music-s.jpg"
    },{
      "pagePath": "pages/music2/music2",
      "iconPath": "/image/playing.jpg",
      "selectedIconPath": "/image/playing-s.jpg",
      "text": "正在播放"
    },{
      "pagePath": "pages/music4/music4",
      "iconPath": "/image/search.jpg",
      "selectedIconPath": "/image/search-s.jpg",
      "text": "搜索"
    }]
  }
}

config.js

(function(module){
  var exports=module.exports={};
  var appid = 63888;
  var secert ="e628f91c466942bab3b7a5c838c742d8";
  var param="?showapi_appid="+appid+"&showapi_sign="+secert;
  var hotUrl="http://route.showapi.com/213-4"+param;
  var searchByNameUrl = "http://route.showapi.com/213-1"+param;
  var searchByIdUrl = "http://route.showapi.com/213-2"+param;

  module.exports={
    config:{
      hotUrl:hotUrl,
      searchByNameUrl:searchByNameUrl,
      searchByIdUrl: searchByIdUrl
    }
  }
})(module);

music1.wxml

<view class='container'>
  <view class='rank-list'>
    <block wx:for="{{ranks}}" wx:key="{{item.type}}">
      <view class='rank-item'>
        <navigator url='/pages/music3/music3?type={{item.type}}' class='text'>{{item.text}}</navigator>
        <view class='arrow'></view>
      </view>
    </block>
  </view>
</view>

music1.js

// pages/music1/music1.js
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    ranks:[
      { type: 26, text: "熱歌" },
      { type: 23, text: "銷量" },
      { type: 18, text: "民謠" },
      { type: 19, text: "搖滾" },
      { type: 5, text: "內(nèi)地" },
      { type: 6, text: "港臺" },
      { type: 16, text: "韓國" },
      { type: 17, text: "日本" },
      { type: 3, text: "歐美" },
    ]
  },

})

music2.wxml

<!--pages/music2/music2.wxml-->
<view class="playing container">
    <view class="thumbnail">
        <image src="{{song.albumpic_big}}" />
    </view>
    <view class="detail">
        <view class="title">{{song.songname}}</view>
        <view class="author">{{song.singername}}</view>
        <view class="action">
            <view class="act-toggle" bindtap="playToggle">
                <image src="/image/{{isPlaying ? 'pause' : 'play'}}.jpg" />
            </view>
        </view>
    </view>
</view>

music2.js

var config = require('../../config.js'); //導(dǎo)入配置文件

// pages/music2/music2.js
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    song: {},  //傳入的歌曲信息
    isPlaying: false, //播放狀態(tài)
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {
    var self = this;
    var songid = options.songid; //獲取頁面跳轉(zhuǎn)傳過來的參數(shù)(歌曲對象)

    if (songid === undefined) { //未傳入歌曲ID
      var curSong = wx.getStorageSync('curSong') || {}; //從緩存中獲取歌曲

      if (curSong === undefined) { //緩存中無歌曲
        var song = { songname: '未選擇歌曲' }; //顯示未選擇歌曲
        this.setData({
          song: song
        })

      } else {
        this.setData({
          song: curSong
        });
      }

    } else {
      var songlist = wx.getStorageSync('songlist') || []; //從緩存中取出歌曲列表
      //在歌曲列表中查找songid指定的歌曲
      for (var i = 0; i < songlist.length; i++) {
        if (songlist[i].songid == songid) {  //找到對應(yīng)的歌曲        
          this.setData({
            song: songlist[i]   //更新歌曲
          });
          break;
        }
      }
      //緩存正在播放的歌曲
      wx.setStorageSync('curSong', this.data.song);
    }
  },
  playToggle: function () {
    var self = this;
    //沒有歌曲要播放,則直接退出
    if (this.data.song.songname == '未選擇歌曲') {
      return;
    }

    if (this.data.isPlaying) { //正在播放
      wx.stopBackgroundAudio(); //停止播放歌曲

    } else {//未播放,則開始播放

      //播放歌曲
      wx.playBackgroundAudio({
        dataUrl: this.data.song.url || this.data.song.m4a,
        success: function (res) { }
      })
    }

    //更新播放狀態(tài)
    this.setData({
      isPlaying: !this.data.isPlaying
    });
  },

})

music3.wxml

<!--pages/music3/music3.wxml-->
<scroll-view scroll-y='true'>
  <view class='board'>
    <image src='{{board}}'></image>
  </view>

  <view class='songlist'>
    <block wx:for="{{songlist}}" wx:key="song_id">
      <view class='songitem'>
        <navigator url="/pages/music2/music2?songid={{item.songid}}" class='song-play'><image src='image/playing.jpg'></image></navigator>
        <navigator url="/pages/music2/music2?songid={{item.songid}}" class='song-detail'>
          <view class='song-title'>{{item.songname}}</view>
          <view class='song-subtitle'>{{item.singername}}-{{item.seconds}}</view>
        </navigator>
      </view>
    </block>
  </view>
  <loading hidden="{{!loading}}">
  正在加載音樂....
  </loading>
</scroll-view>

music3.js

var condig=require('../../config.js');
var formatSeconds=function(value){
  var time=parseFloat(value);
  var m=Math.floor(time/60);
  var s=time-m*60;

  return [m,s].map(formatNumber).join(':');

  function formatNumber(n){
    n=n.toString()
    return n[1]?n:'+n'  
  }
}
// pages/music3/music3.js
Page({

  /**
   * 頁面的初始數(shù)據(jù)
   */
  data: {
    board:'',
    songlist:[],
    loading:false,
  },

  /**
   * 生命周期函數(shù)--監(jiān)聽頁面加載
   */
  onLoad: function (options) {
    var self=this;
    var topid=options.type;

    this.setData({
      loading:true
    })
    wx.request({
      url:config.config.hotUrl,
      data:{topid:topid},

      success:function(e){
        if(e.statusCode==200){
          var songlist=e.data.showapi_res_body.pagebean.songlist;
          for(var i=0;i<songlist.length;i++)
          {
            songlist[i].secondds=formatSeconds(songlist[i].seconds);
          }
          self.setData({
            board:e.data.showapi_res_body.pagebean.songlist[0].albumpic_big,
            songlist:songlist,
            loading:false
          });
          wx.setStorageSync('songlist',songlist);
        }
      }
    });
  },

})

編譯后,如下圖:
圖片描述

點擊后報錯,信息如下:
圖片描述

大佬們幫忙看看 謝謝

回答
編輯回答
懶洋洋

單詞拼錯了啊大哥
clipboard.png

2018年6月24日 00:01