mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 06:07:48 +00:00
first commit
This commit is contained in:
commit
e4ba16b9a2
102 changed files with 19066 additions and 0 deletions
40
src/store/index.js
Normal file
40
src/store/index.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import Vue from "vue";
|
||||
import Vuex from "vuex";
|
||||
import state from "./state";
|
||||
import mutations from "./mutations";
|
||||
import actions from "./actions";
|
||||
import initState from "./initState";
|
||||
import { Howl } from "howler";
|
||||
|
||||
if (localStorage.getItem("appVersion") === null) {
|
||||
localStorage.setItem("player", JSON.stringify(initState.player));
|
||||
localStorage.setItem("settings", JSON.stringify(initState.settings));
|
||||
localStorage.setItem("appVersion", "0.1");
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
Vue.use(Vuex);
|
||||
const saveToLocalStorage = (store) => {
|
||||
store.subscribe((mutation, state) => {
|
||||
// console.log(mutation);
|
||||
localStorage.setItem("player", JSON.stringify(state.player));
|
||||
localStorage.setItem("settings", JSON.stringify(state.settings));
|
||||
});
|
||||
};
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: state,
|
||||
mutations,
|
||||
actions,
|
||||
plugins: [saveToLocalStorage],
|
||||
});
|
||||
|
||||
store.state.howler = new Howl({
|
||||
src: [
|
||||
`https://music.163.com/song/media/outer/url?id=${store.state.player.currentTrack.id}`,
|
||||
],
|
||||
html5: true,
|
||||
format: ["mp3"],
|
||||
});
|
||||
|
||||
export default store;
|
||||
Loading…
Add table
Add a link
Reference in a new issue