<p>这是我的json的样子。我想要在模态框中显示我点击的元素的数据。</p>
<pre class="brush:php;toolbar:false;">[{
"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"
}
]
现在我想要访问jobDescription并在模态框中显示它。</pre>
<pre class="brush:php;toolbar:false;">b-modal(hide-footer="", :id="id")
template(#modal-title="")
| 信息
.d-block.text-center
p {{ 在这里想要jobDescription }}
b-button(variant="primary") 应用</pre>
<p>这是我打开模态框的方式。</p>
<pre class="brush:php;toolbar:false;">openModal(item) {
this.offer = item;
this.$bvModal.show(this.id);
}</pre>
v-for用于循环遍历一组数据,这不是你想要的。假设id是你的json中的标识符,尝试这样做:b-modal(hide-footer="", :id="id") template(#modal-title="") | 信息 .d-block.text-center p() {{ offers[id].jobDescription }} b-button(variant="primary") 申请如果你将选定的
id存储为数据变量,你可以将其放在计算属性中:computed: { selected() { return this.offers[this.id].jobDescription; } }(编辑:我没有意识到你发布了你的json,我之前的回答是针对数组的)