需求:
要獲取用戶離開當前頁面時的音樂播放時長,然後post給後臺
/* 數據序列化 */
function transformRequest(data){
var ret = '';
for(var it in data){
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret;
}
axios.post(baseURL,transformRequest({
api_token : self.api_token,
member_id : self.member_id,
course_id : self.course_id,
second : self.play_time
}).then(function(res){
console.log(res);
}).catch(function(error){
console.log(error);
});