nodejs-- vuex中mapActions
生活随笔
收集整理的這篇文章主要介紹了
nodejs-- vuex中mapActions
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
mapActions() 返回的是一個對象, 用了 ... 擴展符后,才可以放進一個對象里,和其他組件內定義的 method 在同一個 methods 對象。
?
?
{
methods: mapActions() // 如果沒有其它組件內的定義的方法,可以這樣寫
}
{
methods: {
...mapActions(),// 如果有其他定義的方法
otherMethod1 () {},
otherMethod2 () {}
}
?
?
?
}
假設mapActions(),返回的是
{a() {},b() {} }那 ...mapActions(),只不過是把a,b都拿出來跟其他方法放在一起了而已。
...代表兩種意思,一種是剩余操作符,一種是擴展運算符,你題目里用的那個應該是剩余操作的意思,而...mapActions才是擴展運算符。
?
?
其中參數的使用方法原理為::
?
?
methods: {'some/nested/module/foo': (val) {return this.$store.dispatch('some/nested/module/foo', val)) } }但這個Mutations這么長, 一般不會這樣去轉換,會加個別名
methods: {...mapActions({foo: 'some/nested/module/foo',bar: 'some/nested/module/bar'}) }//相當于下面的寫法methods: {foo(val){return this.$store.dispatch('some/nested/module/foo', val)) } //bar 省略.... }) }轉載于:https://www.cnblogs.com/cxiang/p/10528329.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的nodejs-- vuex中mapActions的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: k8s部署jar包_使用Kubernet
- 下一篇: quartz 每月一次_Quartz C