<div class="history">
<ul>
<template v-for="(item,index) in historyList.elementList" >
<li :id="('lishi_'+index)" :key="index" :class="{'historyHover':pos==2&&itemNo==(index)}" >
<img :src="item.assetImg?item.assetImg:item.elementImg" />
<div class="h_progress" v-show="!(pos==2&&itemNo==(index))">
<p v-show="item.assetType!= undefined && item.assetType!='Movie'">第{{parseInt(item.episode)}}集</p>
<p v-if="item.recordTime!= undefined && item.recordTime!= '0'">观看至{{getWatchTime(item.recordTime,index)}}</p>
</div>
<span class="history-title" v-show="(pos==2&&itemNo==(index))">{{item.assetName?item.assetName:item.elementName}}</span>
</li>
</template>
</ul>
</div>
created () {
this.jsonData = this.initData;
if (this.jsonData.elementList[0].elementList){
this.eleId = this.jsonData.specialId;
this.swipeList = this.jsonData.elementList[0].elementList;
this.bgPhoto = this.swipeList[0].elementImg;
this.rec = this.jsonData.elementList;
this.historyList = this.jsonData.elementList[3];
this.timeTask();
}
try {
let historyData = JSON.parse(localStorage.getItem('historyList'));
console.log(historyData);
console.log('历史记录类型' + JSON.stringify(historyData));
if (historyData.length == 0) return;
if (historyData.length >= 2){ historyData = historyData.slice(0, 2) };
this.historyList.elementList = historyData;
} catch (error) {
}
},
activated () {
try { // 缓存被激活需要重新获取历史记录
let historyData = JSON.parse(localStorage.getItem('historyList'));
console.log('缓存激活' + JSON.stringify(historyData));
if (historyData.length == 0) return;
if (historyData.length >= 2){ historyData = historyData.slice(0, 2) };
this.historyList.elementList = historyData;
} catch (error) {
console.log('获取历史记录异常');
}
},
methods: {
getWatchTime (ms, index){
console.log('当前历史记录位置:' + index);
console.log('当前观看时间毫秒:' + ms);
// return new Date(parseInt(ms)).format('mm:ss');
},
有人知道嘛!
老铁,写法有问题
这么写在渲染的时候就直接调用方法了,你应该是在某些时候来触发这个方法,比如点击事件或者其他