<script>
import axios from 'axios'
export default {
data () {
return {
firstRecord: 1,
count: 6,
searchResult: this.loadSearchResult()
}
},
methods: {
loadSearchResult () {
return axios.get(store.state.serviceUrl+ 'boxes?q=' + this.$route.query.stext + '&firstRecord=' + 1 + '&count=' + 9)
.then((response) => {
return response.data.response.data
})
}
}
}
</script>
Why loadSearchResult returns empty to caller?
...
.then((response) => {
return response.data.response.data
})
...
Maybe is thisundefined ? axios' data is only in the response.data.
If not, the uri seems a bit off
store.state.serviceUrl+ 'boxes?q=' + this.$route.query.stext + '&firstRecord=' + 1 + '&count=' + 9
Shouldn't this be
this.$store.state.serviceUrl+ 'boxes?q=' + this.$route.query.stext + '&firstRecord=' + 1 + '&count=' + 9
@Kylart i did console.log it outputs data.
Maybe asyncData would be of use here then ?
...
async asyncData () {
const { data } = await axios.get(`store.state.serviceUrl+ 'boxes?q=' + this.$route.query.stext + '&firstRecord=' + 1 + '&count=' + 9`)
return {
searchResult: data.response.data
}
}
...
axios module for nuxt is now ready. You may give it a try ;)
As say @Kylart for this case is not necessary axios, only you should to use searchResult: this.$store.state.....
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Maybe asyncData would be of use here then ?