异常与错误
const Store = require('electron-store')
const uuidv4 = require('uuid/v4')
const path = require('path')
class DataStore extends Store {
constructor(setting) {
super(setting)
this.tracks = this.get('tracks') || []
}
//保存
saveTracks() {
this.set('tracks', this.tracks)
return this
}
//获取
getTracks() {
return this.get('tracks') || []
}
addTracks(tracks) {
//重新组装对象
const tracksWithPops = tracks.map(track => {
return {
id: uuidv4(),
path: track,
fileName: path.basename(track)
}
})
.filter(track => {
const currentTrackPath = this.getTracks().map(track => track.path)
return currentTrackPath.indexOf(track.path) < 0
})
this.tracks = [...this.tracks, ...tracksWithPops]
return this.saveTracks()
}
}
module.exports = DataStore,
.filter(track => {
const currentTrackPath = this.getTracks().map(track => track.path)
return currentTrackPath.indexOf(track.path) < 0
})
这段代码中this.getTracks()返回的不是数据,是一个对象,这是什么问题?谢谢