vue与vuex计算属性不更新

时间:2017-11-20 07:57:56

标签: vue.js vuex

我正在使用vuex和socket.io来进行state.Nodes.nodes更新。我正在更新单个节点(索引4),当我使用setInterval记录output_state和计算完全相同的属性(node 4 output_state)时 - 它们在变异后会有所不同!

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>5.0.1.RELEASE</version>
    </dependency>

突变是这样完成的:

computed: {
  tmpStatus () {
    if (this.$store.state.Nodes.nodes.length !== 0) {
      return this.$store.state.Nodes.nodes[4].output_state
    } else {
      return null
    }
  }
},
created () {
  this.debugInterval = setInterval(() => {
    console.log('Devicesstate', this.$store.state.Nodes.nodes[4].output_state, this.tmpStatus)
  }, 2000)
},
更新前的

结果(两者都相同): let nodeFound = state.nodes.filter(item => item.node_id === node.node_id)[0] let nodeIndex = state.nodes.indexOf(nodeFound) state.nodes[nodeIndex] = node

更新后的

结果 - 更改为false(它们不同!): Devicesstate true true

我已经改变了这种突变(将Vue导入文件):

Devicesstate false true

它有效。

1 个答案:

答案 0 :(得分:1)

我已经改变了这种突变(将Vue导入文件):

Vue.set(state.nodes, nodeIndex, node)

它有效。

相关问题