javascript - js中括号问题
问题描述
import {INCREMENT} from './types'const mutations = { [INCREMENT] (state) { state.count++; }}
[INCREMENT] INCREMENT是变量直接使用不就行了吗,为什么还要加一个中括号呢?
问题解答
回答1:[INCREMENT]是计算INCREMENT这个变量的值作为函数名,不使用中括号是把INCREMENT这个字符串作为函数名。
const INCREMENT = ’myfunc’;const mutations = { [INCREMENT] (state) { state.count++; }}
相当于上面的代码,结果是
const mutations = { myfunc(state) { state.count++; }}
而
const INCREMENT = ’myfunc’;const mutations = { INCREMENT (state) { state.count++; }}
的结果是
const mutations = { INCREMENT(state) { state.count++; }}回答2:
这是 computed property names
https://developer.mozilla.org...
相关文章:
1. apache - 怎么给localhost后面默认加上8080端口2. docker-compose中volumes的问题3. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题4. angular.js - 百度支持_escaped_fragment_吗?5. javascript - vue $set 整个数组6. php mail无法发送邮件7. python - 管道符和ssh传文件8. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?9. 新手 - Python 爬虫 问题 求助10. vim - win10无法打开markdown编辑器
