javascript - 页面created的时候触发action进行请求,发现vuex state中的状态确实发生了变化,但是页面需要刷新才能渲染列表?

 夕祈文_279 发布于 2022-11-27 07:39
  1. 为什么我的页面created的时候触发action进行请求数据,

created () {
    this.postEvent()
  },
  methods: {
    ...mapActions([
      'changeatteintionList'
    ]),
    postEvent () {
      this.message.bankId = this.collectItems.ologoinMessage.obj_bak2.bankId
      this.changeatteintionList(this.message) // 触发action
    }
    
    action中的代码:
import {ajaxPost} from '../../commonJS/hashParam.js'
import {roleSearchApi} from '../../api.js'
export default {
  changeatteintionList ({commit, state}, data) {
    console.log(data)
    // commit('changeatteintionList', data)
    ajaxPost(roleSearchApi, data, (response) => {
      if (response.data.status === 'success') {
        console.log(window.JSON.stringify(response.data.obj))
        commit('changeatteintionList', response.data.obj)
      }
    })
  }
}

mutations中的代码:

changeatteintionList (state, data) {
    sStorage(state, 'oatteintionList', data)
  },

但是发现vuex state 中对应状态发生了变化,但是需要刷新后,页面中的列表才能渲染成功?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有