Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将数组传递给modal?_Javascript_Vue.js - Fatal编程技术网

Javascript 如何将数组传递给modal?

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="

我使用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">
    <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;
  }
}