我正在使用Axios从REST API获取国家/地区列表,因此我设置了每个都有国家/地区名称和标志的模式。
单击任何国家名称后,控制台将记录该国家。
我有一个历史模式,我希望将过去的5个国家/地区传递给它。
<!-- 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(country) {
console.log("Clicked on: " + country.name);
},
您可以在中创建一个循环缓冲区,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;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句