There are 4 routing components A, B, C, and D under the parent component APP. There are A1, B1, C1, and D1 subcomponents under these 4 routing components. There is also an E component under the app. When these components A1, B1, C1, and D1 are clicked, the methods in the E component are triggered and the corresponding parameters are passed to the methods in the E component. Now my method is to use
this.$emit一层一层往上传递到父组件然后使用this.$refs 这样的方法激活E组件的方法和传递数据.
后来觉得这样麻烦就使用vuex, 把要传递的数据都放进store里面,但是不知道怎么使用vuex让E组件的方法在我点击后自动触发
You can set the value of E component
computed store
, and thenwatch
this value, and then triggerwatch
'shandler
according to the value ofstore
. If you need to trigger it every time you click on the same component, you need to trigger it every time Every click changes a value, andcomputed
should be cached.A better way would be to write an
action
asvuex
, and then import thisaction
in each component, and you can use it.