Questions about vuex...mapActions - Stack Overflow
黄舟
黄舟 2017-06-12 09:32:30
0
2
764

I know... is the spread operator of ES6. And can be used like this

var {a,...b} ={x:1,y:2,z:3};
//a=1 b={y:2,z:3}

But I really don’t understand what it means to use...mapActions() in the methods attribute of vue.
God please answer!

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
黄舟

mapActions() returns an object. Only after using the ... extension character can it be put into an object and be in the same methods object as the methods defined in other components.

{
    methods: mapActions() // 如果没有其它组件内的定义的方法,可以这样写
}
{
    methods: {
        ...mapActions(),// 如果有其他定义的方法
        otherMethod1 () {},
        otherMethod2 () {}
    }
}
为情所困

Correct solution upstairs, assuming mapActions() returns

{
    a() {},
    b() {}
}

Then...mapActions() just takes out a and b and puts them together with other methods.
... represents two meanings, one is the remainder operator and the other is the expansion operator. The one used in your question should mean the remainder operation, and...mapActions is the expansion operator.
Details: https://developer.mozilla.org...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template