JavaScript/vue.js/store:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
第11行: 第11行:
流程图如下
流程图如下
[[文件:Vue new store 1.png|700px|无|none|Vue new store 1]]
[[文件:Vue new store 1.png|700px|无|none|Vue new store 1]]
现在的问题是上传结束后,store 更新后,组件中的 store 值依然是上次的值(等于视图组件值没有更新)。
<s>以下是尝试后的失败的方法</s>
<syntaxhighlight lang="javascript">
data () {
  return {
    sessionid: this.$store.state.file.sessionid
  };
},
computed: {
  watchSid () {
    // 需要监听的数据
    return this.$store.state.file.sessionid
  }
},
watch:{
  watchSid:{
    handler (val){
      this.sessionid = val
    },
    deep:true,
    immediate:true
  }
},</syntaxhighlight>
我试图通过监听 store 的值变化来更新组件的 data(通过 data 中转并缓存 sessionId),并没有管用。
所以换另一种方法: