반응형
Vuex 커밋이 v-show를 트리거하지 않음
vuex를 처음 시도하고 있는데 스토어에서 변환 커밋 후 v-show 지시문이 트리거되지 않았습니다.
// store.js
import Vue from "vue"
import Vuex from "vuex"
const states = {
app: {
init: "APP_INIT"
}
}
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
appState: ""
},
mutations: {
changeAppState (state, appState) {
state.appState = appState
}
},
getters: {
isVisible: state => state.appState === states.app.init
}
})
export { store }
컴포넌트 A표시하다
<template v-show="isVisible">
<div id="componentA"></div>
</template>
<script>
export default {
name: "ComponentA",
computed: {
isVisible () {
return this.$store.getters.isVisible
},
appState () {
return this.$store.state.appState
}
},
watch: {
appState (newVal, oldVal) {
console.log(`Changed state: ${oldVal} => ${newVal}`)
}
},
mounted () {
setTimeout(() => {
this.$store.commit("changeAppState", "APP_INIT")
}, 1000)
}
}
</script>
<style scoped lang="scss">
#componentA {
width: 400px;
height: 400px;
background: red;
}
</style>
정의했습니다.getter isVisible평가해야 할 것은true만약state.appState속성은 문자열과 동일합니다.APP_INIT돌연변이에 대한 확약이 반응 시스템을 작동시켜 시야를 다시 렌더링할 것이라고 생각했지만, 이는 일어나지 않았습니다. 왜일까요?
루트에 지시어를 적용할 수 없습니다.<template>이런 거죠.내부 요소를 사용해야 합니다.
<template>
<div v-show="isVisible">
...
</div>
</template>
또, Vue docs 상태에도 주의해 주세요.
주의:
v-show를 지원하지 않습니다.<template>또, 이 요소에서는 동작하지 않습니다.v-else.
언급URL : https://stackoverflow.com/questions/55172196/vuex-commit-does-not-trigger-v-show
반응형
'source' 카테고리의 다른 글
| 메서드에 대한 Java 변수 인수 수 (0) | 2022.08.29 |
|---|---|
| AWS 오류 메시지:이 리소스에 대해 충돌하는 조건부 작업이 현재 진행 중입니다. (0) | 2022.08.29 |
| Element UI Input v2.x에 입력할 때 값을 내보내는 방법 (0) | 2022.08.29 |
| 제목에 링크가 있는 Bootstrap-Vue (0) | 2022.08.29 |
| Java로 기간을 포맷하는 방법(예: H 형식:MM:SS) (0) | 2022.08.29 |