i'm making CRUD admin tool using Nuxt.js (Vue.js SSR framework) but when object more nested, it is difficult to handling this objects.
for example, when i have object like this
in A.vue file
data: () => ({
page: {
language: "",
background: "",
content: {
title: "",
age: {
male: ["......."],
female: ["...."]
}
}
...and more complex
}
})
i want using class model like this,
in A.vue file
data: () => ({
page: new Page();
})
in Class files...
class Page() {
language, background, content properties...
}
class Content() {
title, age properties...
}
class Age() {
male, female properties...
}
but class is not a pure object, it does not match the concept of vue.js (Vue will walk through all of its properties and convert them to getter/setters using Object.defineProperty.)
so, i used util function that get data, and returning page object with default values,
in A.vue
data: () => ({
page: getPageObject()
})
in PageUtils.js
function getPageObejct(data) {
return {
....data,
language: 'en',
background: '',
content: {
title: 'title'
....
}
}
}
...but i don't think that best way of handle complex data
how can i using class or other mapping model for convenient using data? (default value, method..)