search

Home  >  Q&A  >  body text

javascript - How to use data to save the value obtained by vuex's getters in the vue component


I obtained a user object like this, how can I use the data inside this component to store the value of this user object to avoid directly modifying vuex when v-modal the value

PHP中文网PHP中文网2750 days ago675

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-19 10:10:08

    // ...
    data: {
      // 组件初始化时从 vuex user 中获取值
      privateUser: this.user
    }
    watch: {
      // 当 vuex 的 user 值变更时同步 data 属性
      user (newVal) {
        this.privateUser = newVal
      }
    }

    reply
    0
  • 黄舟

    黄舟2017-05-19 10:10:08

    computed: {
        userName () {
            return this.user
        }
    }

    reply
    0
  • Cancelreply