Javascript 如何将数组传递给modal?
我使用Axios从RESTAPI获取国家列表,所以我设置了每个有国家名称和国旗的模态 单击任何国家/地区名称,console将记录该国家/地区 我有一个历史模型,我想通过最后5个国家点击它Javascript 如何将数组传递给modal?,javascript,vue.js,Javascript,Vue.js,我使用Axios从RESTAPI获取国家列表,所以我设置了每个有国家名称和国旗的模态 单击任何国家/地区名称,console将记录该国家/地区 我有一个历史模型,我想通过最后5个国家点击它 <!-- History Modal --> <div> <b-button v-b-modal.modal-1>View History</b-button> <b-modal id="modal-1" title="
<!-- History Modal -->
<div>
<b-button v-b-modal.modal-1>View History</b-button>
<b-modal id="modal-1" title="History">
<p class="my-4">{{ country.name }}</p>
</b-modal>
</div>
您可以在
handleClick()
中创建一个循环缓冲区,并传入被单击的国家/地区。这将保留历史记录数组中单击的最后5个国家/地区供您访问
data(){
return{
index: 0,
history: [],
}
},
methods:{
handleClick(data){
console.log("Clicked on: " + data.name);
this.history[this.index] = data;
this.index = (this.index + 1) % 5;
}
}
{{this.history}
在模式中没有返回任何内容,但是javascript是功能性的,我认为@S。Ramjit@AhmadTakkoush它应该是{{{history}}
模板中不需要这个
,谢谢!我有一个问题,它没有得到国家,结果我不得不添加this.fetchData()代码>在我的handleclick函数的末尾。
data(){
return{
index: 0,
history: [],
}
},
methods:{
handleClick(data){
console.log("Clicked on: " + data.name);
this.history[this.index] = data;
this.index = (this.index + 1) % 5;
}
}