the data sent by vue to the ajax request is not saved in vuex"s state
seems to be. In the course of the request, the data is saved, the request ends, and the data is missing again
the code is as follows
data() {
return {
}
},
created(){
console.log(this.$store.state.list) //84
this.getNews()
console.log(this.$store.state.list) //86
},
computed:{
...mapState(["list", "cont", "loading"]),
...mapGetters(["addNews"])
},
methods: {
getNews(){
var url = "http://www.toutiao.com/api/comment/list/?group_id=6364965628189327618&item_id=6364969235889783298&offset=0&count=10"
this.$axios.get(url).then( res=> {
this.$store.state.list = res.data.data.comments
console.log(this.list) //97
})
console.log(this.list) //99
},
the vuex store.js code is as follows
import Vue from "vue"
import Vuex from "vuex"
Vue.use(Vuex)
// data
const state = {
list: [],
loading: false
}
// n
const mutations = {
}
// n
const actions = {
}
// getter
const getters = {
}
export default new Vuex.Store({
state,
mutations,
actions,
getters
})
Output of page after running::