How to pass index from the li to axios?

Viewed 104

      selectPreviousSearch(index) {
        this.search = this.searchHistory.slice(-5).reverse()[index];
        // this.search = this.searchHistory[index];
        this.showSearchHistory = false;
        

        const baseURI = 'api url...';   

        var container_id =  JSON.parse(localStorage.getItem('anonymous_id'));
       
        let accToken = localStorage && localStorage.loggedinUser ? localStorage.loggedinUser : null;
          // eslint-disable-next-line
         console.log('another call',accToken);


        const headers = new Headers({
          'access_token' : accToken,
          'Content-Type': 'application/json',
        });

        var data={

          'keyword': this.index,

        } 

        axios.get(baseURI, data, {
          headers: {
            'access_token': accToken
          }
        })
        .then((response) => {
          this.users = response;
         
        }, (error) => {
          if (error) {
            this.errorMessage = error.response.data.message;
          }
        }).catch(error => {
          //this.errorMessage = error.response.data;
        })


      },
<li
            v-for="(item, index) in searchHistory
              .slice(-5)
              .reverse()
              .map((s) => s.trim())"
            :key="index"
            @click="selectPreviousSearch(index)"
          >
            {{ item }}
          </li>

I want to pass index from the li to the axios? inside of the var data. So that when user clicked on data form the li. He will get the success response.

At present i am thinking that, I have not passed the value correctly, from the li So that i am unable to see proper response

1 Answers

try to pass get params like this

axios.get(baseURI, {
   params: data,
   headers:...
})

Examples in docs https://github.com/axios/axios#example

Or change

axios.get

to

axios.post

Depends on which request type you handle on server side

Related