How to use this.$set to update objects in vuex?

what if mutations uses this.$set to update state object data directly in a separate js file and will report an error this.$set is not a function ?

data in state

articleList: [
    {
      userinfo: {image: "static/img/3.jpeg", nickname: "eee", text: "", time: ""},
      content: {href: "2222222", text: "test", create_time: "", updata_time: ""},
      pic: [{path: "static/img/0.jpg"}, {path: "static/img/0.jpg"}, {path: "static/img/0.jpg"}],
      likebar: {hot: 555, status: false, comments: 666},
      isFollow: true
    }
  ]

component triggers action
this.$store.dispatch ("getLists")

action.js

getLists (val) {
    api.articleList().then((res) => {
      val.commit("updateList", res)
    })
}

mutations.js

updateList (state, data) {
    this.$set(this.state.articleList, 0, data)  //
    this.state.articleList = data //
}
May.09,2022

:

updateList (state, data) {
    state.articleList[0] = data;
    state.articleList = JSON.parse(JSON.stringify(state.articleList));
}

applies to both arrays and objects

Menu