javascript - js square bracket problem
高洛峰
高洛峰 2017-05-16 13:42:12
0
2
603
import {INCREMENT} from "./types"

const mutations = {
    [INCREMENT] (state) {
      state.count++;
    }
}

[INCREMENT] Can't INCREMENT be used directly as a variable? Why do we need to add a bracket?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
黄舟

[INCREMENT]是计算INCREMENT这个变量的值作为函数名,不使用中括号是把INCREMENTThis string is used as the function name.

const INCREMENT = 'myfunc';

const mutations = {
    [INCREMENT] (state) {
      state.count++;
    }
}

Equivalent to the above code, the result is

const mutations = {
    myfunc(state) {
      state.count++;
    }
}

And

const INCREMENT = 'myfunc';
const mutations = {
    INCREMENT (state) {
      state.count++;
    }
}
The result of

is

const mutations = {
    INCREMENT(state) {
      state.count++;
    }
}
phpcn_u1582

These are computed property names

https://developer.mozilla.org...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!