【发布时间】:2021-03-16 06:53:22
【问题描述】:
这就是我的 json 的样子。我以 v-for 格式显示其中的一堆,并且可以单击其中一个。我想在模式中显示我单击的元素中的数据。
[{
"id": 1,
"companyName": "test",
"image": "https://mmelektronik.com.pl/wp-content/uploads/2017/10/Insert-logo.jpg.png",
"location": "Warsaw",
"salary": "10000",
"skill": "Junior",
"tags": "test",
"jobDescription": "test",
"title": "UI Designer"
}
]
Now I want to access only jobDescription and display it in the modal.
b-modal(hide-footer="", :id="id")
template(#modal-title="")
| Information
.d-block.text-center
p {{ want the jobDescription here }}
b-button(variant="primary") Apply
这就是我打开模式的方式。
openModal(item) {
this.offer = item;
this.$bvModal.show(this.id);
}
组件
b-container
b-card.joblist__post.mt-2(
v-for="offer in filteredOffers",
:id="id"
:key="offer.id",
@click="openModal"
)
.d-flex
.joblist.d-flex.w-100
.joblist__info.d-flex.align-items-center
.company-logo.d-flex.align-items-center.mr-3
b-img.logo(:src="offer.image")
.joblist-name.d-flex.flex-column.text-left
h5.mb-0.font-weight-bold {{ offer.title }}
.located.d-flex.align-items-center.mt-2.justify-content-start
b-icon.mr-2(icon="geo-alt-fill")
p.m-0.text-secondary.joblist-span {{ offer.location }}
b-icon.mx-2(icon="person-fill")
p.m-0.text-secondary.joblist-span {{ offer.companyName }}
b-icon.mx-2(icon="bar-chart-fill")
b-modal(hide-footer="", :id="id")
template(#modal-title="")
| Information
.d-block.text-center
p {{offer.jobDescription}}
b-button(variant="primary") Ok
export default {
data() {
return {
search: "",
};
},
computed: {
...mapState({
offers: (state) => state.offer.offers,
loading: (state) => state.offer.loading
}),
filteredOffers(){
return this.offers.filter((offer) => {
return offer.title.match(this.search);
})
},
},
methods: {
...mapActions({
fetchOffers: "fetch",
}),
openModal(item) {
this.offer = item;
this.$bvModal.show(this.id);
}
},
mounted() {
this.fetchOffers();
this.id = this._uid;
},
};
【问题讨论】:
-
您能创建一个可重现的示例吗? ??? stackoverflow.com/help/minimal-reproducible-example
-
你有 v-for 列表作为按钮。您单击一个按钮,模态打开,并且您希望在模态中显示该按钮包含的来自 json 的信息。
-
由于您在父级中设置
this.offer,它应该是可用的。试试{{ offer.jobDescription }} -
@Dan ,不会这样工作,当我这样做时,页面变为空白
-
嗯,这是一个猜测,因为看起来您在父级中设置了
this.offer。但这只是一个猜测,因为您没有显示该组件。你应该证明这一点。也许可以直接从id完成,但这似乎没有必要,取决于父项中定义的内容
标签: javascript vue.js vuejs2 vue-component bootstrap-vue