Skip to content

Instantly share code, notes, and snippets.

@andrewhl
Last active December 10, 2018 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewhl/da431cf1dc264c57c6c44efd2b385b52 to your computer and use it in GitHub Desktop.
Save andrewhl/da431cf1dc264c57c6c44efd2b385b52 to your computer and use it in GitHub Desktop.
export default {
data: [
{
id: 1,
level: 1,
parent_id: null,
children: [ 4,5 ]
},
{
id: 2,
level: 1,
parent_id: null,
children: [ 6 ]
},
{
id: 3,
level: 1,
parent_id: null,
children: []
},
{
id: 4,
level: 2,
parent_id: 1,
children: []
},
{
id: 5,
level: 2,
parent_id: 1,
children: []
},
{
id: 6,
level: 2,
parent_id: 2,
children: []
}
]
}
import sample_data from './sample_data';
const state = Object.assign({}, sample_data);
const getters = {
getLevel: state => level => state.data.filter(item => item.level === level)
}
export default {
namespaced: true,
state,
getters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment