【发布时间】:2021-09-03 06:47:34
【问题描述】:
当用户点击任何包含数据的卡片(数据来自后端 api GET 方法)时,数据应该绑定或显示在弹出卡片上,如何做这件事。在我的情况下,我有两个组件一个是 DisplayNotes.vue,另一个是 UpdateNotes.vue。当用户点击任何显示的卡片时,数据绑定到 updateNotes 卡片(弹出)。如何将该数据传递到弹出卡片,请帮助我解决这个问题。
[DisplayNotes.vue]
<template>
<div class="carddisplay-section" >
<div v-for="note in notes" :key="note.data" id="blur" class="container note">
<div @click="toggle()" class="card-content">
<h5>{{note.title}}</h5>
<p>{{note.body}}</p>
</div>
<div class="import-icons">
<icons class="imported-icons note-icons" />
<button v-if="flag" class="card-button" type="button" @click="handlesubmit();Togglebtn();">Close</button>
</div>
</div>
<div id="popup">
<UpdateNotes/>
</div>
</div>
</template>
<script>
import service from '../service/User'
import icons from './icons'
import UpdateNotes from './UpdateNotes.vue'
export default {
name: 'DisplayNotes',
components: {
icons,UpdateNotes
},
data() {
return {
flag: true,
notes: [{
id: 1,
title: 'Fundoo',
body: 'unlimited notes..'
}, ],
}
},
methods: {
Togglebtn() {
this.flag = !this.flag;
},
async handlesubmit() {
service.userDisplayNotes().then(response => {
this.notes.push(...response.data);
})
},
toggle(){
var blur=document.getElementById('blur');
blur.classList.toggle('active');
var popup=document.getElementById('popup');
popup.classList.toggle('active');
}
}
}
</script>
<style lang="scss">
.carddisplay-section{
display: flex;
align-items: flex-start;
flex-wrap: wrap;
align-content: space-around;
gap: 10px;
}
.container {
height: 180px;
background: #fff;
padding: 7px;
border-radius: 7px;
box-shadow: 5px 5px 10px #e0dede;
margin-top: 5%;
margin-left: 18%;
margin-right: -15%;
float: left;
width: 22%;
}
.card-content {
h5 {
font-size: 20px;
font-weight: 400;
font-family: 'Times New Roman', Times, serif;
padding-left: 10px;
}
p {
font-size: 18px;
width: 90%;
height: 60px;
font-family: 'Times New Roman', Times, serif;
width: 100%;
border: none;
padding: 7.5px 10px;
outline: none;
}
}
.card-button {
float: right;
margin-top: -1px;
margin-left: 240px;
font-size: 14px;
border: none;
background: none;
font-family: 'Times New Roman', Times, serif;
}
.note-icons {
visibility: hidden;
}
.note {
&:hover {
.note-icons {
visibility: visible;
}
}
}
.imported-icons {
margin-top: 10%;
}
#blur.active{
filter:blur(0.5px);
// pointer-events: none;
// user-select: none;
}
#popup{
position: fixed;
top:40%;
left:50%;
transform: translate(-50%,-50%);
visibility: hidden;
opacity: 0;
transition: 0.5s;
}
#popup.active{
visibility: visible;
opacity: 1;
transition: 0.5s;
}
.card-content p,h5 {
word-break: break-word;
overflow-wrap: break-word;
}
</style>
这是我的 updateNotes.vue(弹出卡片) [UpdateNotes.vue]
<template>
<div class="update" >
<form class="update-note" @submit.prevent="handlesubmit" autocomplete="off">
<input name="title" v-model="title" placeholder="Title" />
<textarea name="content" v-model="body" style="resize: none" placeholder="Take a note..." rows="3"></textarea>
<div class="btm-icons">
<icons />
<button id="btn-section" type="submit" >Close</button>
</div>
</form>
</div>
</template>
<script>
import icons from './icons.vue'
export default{
components:{icons},
methods:{
flip() {
this.flag = !this.flag;
},
}
}
</script>
<style scoped>
.update {
padding-top: 0%;
}
.update-note {
position: relative;
width: 550px;
max-width: 100%;
margin: 152px auto;
margin-right: 80%;
background: rgb(255, 255, 255);
padding: 15px;
border-radius: 5px;
box-shadow: 0 1px 5px #ccc;
}
.update-note input {
width: 100%;
max-width: 100%;
border: none;
padding: 4px;
outline: none;
font-size: 1.2em;
}
textarea {
width: 100%;
max-width: 100%;
border: none;
padding: 4px;
outline: none;
font-size: 1.2em;
}
button {
border: none;
background: transparent;
font-weight: 500;
float: right;
margin-top: -5%;
cursor: pointer;
}
</style>
【问题讨论】:
标签: javascript html css vue.js sass