如何显示单击的项目(由循环生成)的属性?
在我的vue3应用中,我有三个板:
- 一个用于拖动元素(已经在JSON文件中定义)
- 一个用于辍学元素的一个(存储在VUE中的空列表中)
- <强>一个显示掉落元素的属性的一个,当您单击它
时,我将使用Vuedragggggggggggggggg =::: img
我的问题是在第三板上:我想单击“ Drop板”中的项目并将其属性显示到“属性板”中,知道项目具有多个属性。 我已经尝试了好几天了,仍然找不到解决方案,有人可以帮我吗?
我是Vue和Stackoverflow的新手,我试图尽可能清楚,如果我犯了错误,我很抱歉。
主页
<template>
<div>
<Board v-for="(board, index) in boards" :key="index" :id="index" :board="board"/>
</div>
</div>
</template>
<script>
import Board from "@/components/Board.vue";
export default {
components: {
Board,
},
data: () => ({
boards: [
{
title: "Toolbox Board",
},
{
title: "Mockup Board",
},
{ title: "Properties" },
],
}),
};
<div class="dd-container" v-if="board.title == 'Toolbox Board'">
<draggable v-model="dragItems" item-key="id":group="{ name: 'items', pull: 'clone', put: false }" :clone="cloneItems" @change="log">
<template #item="{ element }">
<div class="item">
{{ element.title }}
</div>
</template>
</draggable>
</div>
。董事会“代码:
<div class="dd-container" v-if="board.title == 'Mockup Board'">
<draggable
v-model="dropItems" item-key="id" group="items" @change="log">
<template #item="{ element }">
<div class="item">
{{ element.title }}
</div>
</template>
</draggable>
</div>
板。
<div class="dd-container" v-if="board.title == 'Properties'">
{{ property }} ??
</div>
import dragItemsList from "/dragItems.json";
import draggable from "vuedraggable";
export default {
components: {
draggable,
},
data() {
return {
dragItems: dragItemsList,
dropItems: [],
In my vue3 app I have three boards :
- one for draggable elements (already defined in a JSON file)
- one for droppable elements (stored in a empty list in the vue)
- one to display the properties of a dropped element, when you click on it
I'm using Vuedraggable for the drag and drop and here's how it looks : IMG
????My problem is on the third board : I want to click on an item in the "drop board" and show its properties into the "properties board" knowing that an item have multiple properties.
I've tried for days and still can't find the solution, can somebody help me please?
I'm new to Vue and StackOverflow, I've tried to be as clear as possible, sorry if I made mistakes.
Home.vue - first of all, where I declare my boards :
<template>
<div>
<Board v-for="(board, index) in boards" :key="index" :id="index" :board="board"/>
</div>
</div>
</template>
<script>
import Board from "@/components/Board.vue";
export default {
components: {
Board,
},
data: () => ({
boards: [
{
title: "Toolbox Board",
},
{
title: "Mockup Board",
},
{ title: "Properties" },
],
}),
};
Board.vue - The "drag board" code:
<div class="dd-container" v-if="board.title == 'Toolbox Board'">
<draggable v-model="dragItems" item-key="id":group="{ name: 'items', pull: 'clone', put: false }" :clone="cloneItems" @change="log">
<template #item="{ element }">
<div class="item">
{{ element.title }}
</div>
</template>
</draggable>
</div>
????Board.vue - The "drop board" code:
<div class="dd-container" v-if="board.title == 'Mockup Board'">
<draggable
v-model="dropItems" item-key="id" group="items" @change="log">
<template #item="{ element }">
<div class="item">
{{ element.title }}
</div>
</template>
</draggable>
</div>
???? Board.vue - The "properties board":
<div class="dd-container" v-if="board.title == 'Properties'">
{{ property }} ??
</div>
????Board.vue - Some of the script :
import dragItemsList from "/dragItems.json";
import draggable from "vuedraggable";
export default {
components: {
draggable,
},
data() {
return {
dragItems: dragItemsList,
dropItems: [],
????DragItems.json - Most importantly the JSON file :
[
{"title": "Simple list","id": 1,"properties": ["this is a property"],"fixed": true},
{"title": "Search list","id": 2,"properties": ["this is a property"],"fixed": true},
{"title": "Simple options","id": 3,"properties": ["this is a property"],"fixed": true},
{"title": "Multiple options","id": 4,"properties": ["this is a property"],"fixed": true },
{"title": "Location","id": 5,"properties": ["this is a property"],"fixed": true},
{"title": "Picture","id": 6,"properties": ["this is a property"],"fixed": true},
{"title": "Signature","id": 7,"properties": ["this is a property"],"fixed": true},
{"title": "Audio","id": 8,"properties": ["this is a property"],"fixed": true},
{"title": "Todo list","id": 9,"properties": ["this is a property"],"fixed": true},
{"title": "Grouped items","id": 10, "properties": ["this is a property"],"fixed": true},
{"title": "Divider","id": 11, "properties": ["this is a property"],"fixed": true},
{"title": "Grouping container","id": 12, "properties": ["this is a property"],"fixed": true},
{"title": "NFC reader","id": 13, "properties": ["this is a property"],"fixed": true},
{"title": "QR code scanner","id": 14, "properties": ["this is a property"],"fixed": true},
{"title": "Barcode scanner","id": 15, "properties": ["this is a property"],"fixed": true},
{"title": "Fingerprint read (Idemia)","id": 16, "properties": [],"fixed": false}
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您已经将自己放在角落里,因为您试图在不需要的地方使用V-For,列表看起来相同,但是您可以将它们作为碰巧使用相同类别的单独组件。
第二个问题是您要超载板。
如果每个董事会的行为与其他董事会的行为不同,则将这些部分分为自己的组成部分。
因此,您最终会得到3个板组件,每个组件都显示不同的板。
走上路线,强迫模板在两种不同类型的列上使用v-for的路线不是很好的工作,因为您不应该将可拖动的列表和属性窗格放在同一V-For循环中。
因为拖放板都在使用拖放板,所以您可以制作一个单个板组件,以显示可拖动的项目列表,然后在将项目删除到板上时发射事件(例如
drop
) 。因为您共享这些董事会共享的摘要的差异是在拖动的配置中代码> allow-drop )。
在此片段中,
@Select
事件是由板发出的,当选择项目时,董事会发出了事件,因此,HOME组件可以将其设置为焦点项目并将其绑定到属性板以显示其属性。I think you have put yourself into a corner because you are trying to use v-for where it is not needed, the lists look the same but you can just have them as separate components that happen to use the same classes.
Second problem is that you are overloading the Board.vue component with 3 different implementations.
If there are three boards that each behave differently from the others, then split those parts into their own components.
So you would end up with 3 board components, each displaying a different kind of board.
Going your route, of forcing the templating to use a v-for over two different types of columns is not working out well, because you shouldn't put draggable lists and a properties pane in the same v-for loop.
Because the drag and drop boards both are using draggable, you could make a single Board component that would present a draggable list of items and then emit an event (e.g.
drop
) when an item is dropped onto the board.Because the difference in the snippets you shared for those boards was in the configuration of draggable, you can create props for enabling/disabling the drag-and-drop features for those boards (e.g.
allow-drag
,allow-drop
).In this snippet the
@select
event is emitted by the boards when an item is selected, so the Home component can then set it as the focussed item and bind it to the PropertiesBoard to display its properties.