In vue, the interface depends on the change of the previous value, and the corresponding request optimization is made.

clipboard.png
watchmixinswatchloadingaxioshttploading
clipboard.png

1. Can you go to this.store.actions ("getList") as soon as you enter through the vuex, page? I tried to write
const actions = {
getGradeList ({commit}) {

.
this.$request(this.$api.home_list).then(res => {
  console.log("res111", res)
}).catch(err => {
  console.log("err", err)
})
commit()

},
}
will report an error home_list is not defined, and the this introduced by the Vue instance is also reported as an error. What should I pay attention to when I hang up and request the backend interface in actions?
2. If there is a drop-down box like this, it depends on the previous value. It is recommended that it be encapsulated into a component (whether it will be more common)

.
Nov.26,2021

does not quite understand that the landlord will have a change in the previous value of , then there are two http requests . According to personal understanding, when the page begins to load, request the interface of grade , and do not set immediate of watch to true . You can put it in the created method.


axios the list of each request is recorded in the interceptor. After the request is completed, it is emptied. When the request is the same, cancel the previous one or return the previous promise .

Menu