таблица данных не обновляется при добавлении нового объекта vuex - PullRequest
0 голосов
/ 28 апреля 2020

Я хочу добавить новый навык в свою таблицу навыков, но он не обновляется, когда я добавляю новый, вот мой код

Действия

    attachSkill({ context, commit }, query) {
    let url = "/employees/" + query.user + "/skills/" + query.skill;
    const data = {
      note: query.note,
    };

    const headers = {
      "x-api-key": process.env.VUE_APP_SIRH_X_API_KEY,
      Authorization: localStorage.getItem("access_token"),
    };

    return axios({
      method: "post",
      url: url,
      data: JSON.stringify(data),
      headers: headers,
    })
      .then((response) => {
        console.log("response", response);
      })
      .catch((e) => {
        console.log(e);
      });
  },

Vue Компонент

здесь я использую mapActions

...mapActions(["getEmployeeInfo", "attachSkill", "getSkills"]),

   submitattachment() {
  this.dialog = false;
  this.query.user = this.userId;
  this.query.skill = this.skill_list.indexOf(this.query.skill) + 1;

  this.attachSkill(this.query)
    .then(() => {
      this.this.getEmployeeInfo(this.userId);
      this.showSnackbar({
        text: "Skill Created Successfully",
        timeout: 2000,
        color: "primary"
      });
    })
    .catch(error => {
      this.showSnackbar({
        text: error.response.data.message,
        timeout: 2000,
        color: "danger"
      });
    });
},

PS: в чем разница между использованием mapActions и диспетчеризацией

...