sourcecode

vuex 계산 속성이 무효가 아님

copyscript 2022. 8. 8. 20:00
반응형

vuex 계산 속성이 무효가 아님

test.vue, vue 구성 요소에서 'test' 속성은 반응하지만 vuex 저장소의 'title' 속성은 반응하지 않습니다.비슷한 질문을 몇 개 찾았는데 해결 방법이 안 맞네요. 제가 여기서 뭘 잘못했나요?

템플릿

<div class="title">
  <input 
    type="text" 
    placeholder="palceholder" 
    v-model="title"
   />
</div>
<input v-model="test"/>
<div>{{test}}</div>
<div>
  {{title}}
</div>

js

data() {
  test: 'test'
},
computed: {
  ...mapGetters(['article']),
  title: {
    get () { 
       return this.article.title || '' 
    },
    set (value) { this.$store.commit(Types.UPDATE_TITLE, value) }
  }
}

store.displaces를 설정합니다.

import * as Types from '../mutation-types'
import Vue from 'vue'
const state = {
  article: {}
}

const getters = {
  article: state => state.article
}

const mutations = {
  [Types.UPDATE_TITLE] (state, title) {
    state.article = { ...state.article, title }
  }
}

언급URL : https://stackoverflow.com/questions/48802249/vuex-computed-properties-are-not-reactive

반응형