phonesProcessed() {
const classes = Object.fromEntries(this.classes.map(({ classinfoName: c, items }) => [
c,
Object.fromEntries(items.map(n => [
n[`id${c[0].toUpperCase()}${c.slice(1)}`],
n.name,
])),
]));
return this.phones.map(n =>
Object.fromEntries(Object.entries(n).map(([ k, v ]) => [
k,
classes.hasOwnProperty(k) ? classes[k][v] : v,
]))
);
},
created() {
[
[ '5ad979f4-7393-11ea-b9b1-d7fe1923484d', 'classinfo', 'classes' ],
[ '46bf408d-739d-11ea-b9b1-5301e3b2b9ba', 'phones', 'phones' ],
].forEach(([ key, apiPropName, componentPropName ]) => {
axios
.get(`https://jsonblob.com/api/${key}`)
.then(({ data: { [apiPropName]: d } }) => this[componentPropName] = d)
.catch(e => this.errors.push(e));
});
},
computed: {
groupedItems() {
const { items } = this;
const statuses = [...new Set(items.map(n => n.status))];
const positions = [...new Set(items.map(n => n.position))];
return items.reduce(
(acc, n) => (acc[n.status][n.position].push(n), acc),
Object.fromEntries(statuses.map(status => [
status,
Object.fromEntries(positions.map(position => [
position,
[]
]))
]))
);
},
},
<ul>
<li v-for="(statusGroup, status) in groupedItems">
<h2>{{ status }}</h2>
<ul>
<li v-for="(positionGroup, position) in statusGroup">
<h3>{{ position }}</h3>
<ul>
<li v-for="n in positionGroup">{{ n.name }}</li>
</ul>
</li>
</ul>
</li>
</ul>
name: 'v-tree',
props: [ 'items' ],
<ul v-if="items instanceof Object">
<li v-for="n in items">
<b>{{ n.name }}</b>
<v-tree :items="n.children" />
</li>
</ul>
const group = (arr, keys) =>
arr.reduce((acc, n) => {
keys.reduce((g, k, i, a) => {
const name = n[k];
return (g[name] = g[name] || {
name,
children: i === a.length - 1 ? [] : {},
}).children;
}, acc).push(n);
return acc;
}, keys.length ? {} : []);
computed: {
groupedItems() {
return group(this.items, [ 'status', 'position' ]);
},
},
<v-tree :items="groupedItems" />
data: () => ({
links: [
{ to: '...', title: '...' },
{ to: '...', title: '...' },
...
],
}),
<ul>
<router-link v-for="n in links" :to="n.to" v-slot="s">
<li :class="{ active: s.isExactActive }">
<a :href="s.href" @click="s.navigate">{{ n.title }}</a>
</li>
</router-link>
</ul>
.map(n => ({ ...n, actv: false }))
.map(n => (n.actv = false, n))
или после монтирования компонента?
mounted() {
this.postsData.forEach(n => this.$set(n, 'actv', false));
},
mounted() {
this.postsData = this.postsData.map(n => ({ ...n, actv: false }));
},
computed: {
tasksGroupedByCategory() {
return this.tasks.reduce(
(acc, n) => (acc[n.category].push(n), acc),
Object.fromEntries(this.boards.map(n => [ n.name, [] ]))
);
},
},
<div v-for="b in boards">
<h2>{{ b.title }}</h2>
<div v-for="n in tasksGroupedByCategory[b.name]">
{{ n.title }}
</div>
</div>
@click="testClickGo().restart"
targets: '.testVal',
data: () => ({
anime: null,
}),
mounted() {
this.anime = this.$anime({
targets: this.$refs.animeEl,
translateX: 200,
delay: 800,
});
},
<h1 ref="animeEl">hello, world!!</h1>
<button @click="anime.restart()">click me</button>
v-model
.делаю все как показано в примере в оф. репозитории
API: Container
Component that contains the draggable elements or components. Each of its children should be wrapped by Draggable component
<Container @drop="$emit('drop', row.id)" :get-child-payload="getChildPayload"> <div class="row">