Hi,
I want to use item-card to duplicate the self-designed item in template node of dashboard v2, but it does not work as I expected, here is my code, is there something wrong with it?
<template>
<div id="app">
<item-card v-for="(item, index) in items" :key="index" :index="index+1" :title="item.title" :speed="item.speed">
</item-card>
</div>
</template>
<script>
const ItemCard = {
props: ['index', 'title', 'speed'],
template: `
<div class="item-card" @click="toggle">
<div class="left">{{ index }}</div>
<div class="middle">
<div class="title">{{ title }}</div>
<div class="desc">Speed: {{ speed }} mm/s</div>
</div>
</div>
`,
methods: {
toggle() {
console.log('Click ' + this.index);
}
}
};
const app = Vue.createApp({
data() {
return {
items: [
{ title: "Card A", speed: 100 },
{ title: "Card B", speed: 200 },
{ title: "Card C", speed: 300 }
]
}
}
});
app.component('item-card', ItemCard);
app.mount("#app");
</script>
<style>
.item-card {
display: flex;
border: 1px solid #ccc;
border-radius: 8px;
margin: 5px;
padding: 10px;
cursor: pointer;
}
.left {
font-weight: bold;
margin-right: 10px;
}
.middle {
flex-grow: 1;
}
.title {
font-size: 16px;
font-weight: bold;
}
.desc {
font-size: 14px;
color: gray;
}
</style>