Vueでpropsの値の変更を検知する方法はないのでしょうか?
やっていることは、
stateのgettersを通してcountを取得
↓
vuex-connectを用いて定義したcontainersでcomponentを生成
↓
propsバケツリレーで子コンポーネントに渡す
やりたいことは子コンポーネントでのpropsの変更を検知することです。
(mountedに反応するようにしたい)
store/modules/A/index.js
js
1const store = { 2 state () { 3 return { 4 count: 0 5 } 6 }, 7 actions, 8 getters, 9 mutations 10}
containers/generator.js
js
1import { connect } from 'vuex-connect' 2 3import Parent from '../components/parent' 4 5import { Count } from '@/store/modules/A' 6 7export default connect({ 8 gettersToProps: { 9 count: Count 10 }, 11 methodsToEvents: { 12 } 13})('A', Parent)
components/parent/index.vue
vue
1<template> 2<div> 3 <child :count=count /> 4</div> 5</template> 6 7<script> 8export default { 9 components: { child }, 10 props: { 11 count: { 12 type: Number, 13 default: 0 14 } 15 } 16} 17</script>
components/child/index.vue
vue
1<script> 2export default { 3 props: { 4 count: { 5 type: Number, 6 default: 0 7 } 8 }, 9 mounted: function () { // ここで反応して欲しい 10 if (count % 3 === 0) { 11 console.log("Alert") 12 } 13 } 14} 15</script>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/15 06:38
2019/02/15 09:04
2019/02/18 10:10
2019/02/19 00:02