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. linux - 编译安装mysql 5.6.232. angular.js - vue中类似于angular的ng-change的指令是?3. node.js - 微信的自动回复问题4. css3 - 请问一下在移动端CSS布局布局中通常需要用到哪些元素,属性?5. node.js - vue服务端渲染如何部署到线上6. html5 - 在一个页面中 初始了两个swiper 不知道哪里错了 一直不对7. PHP能实现百度网盘的自动化么?8. android - 使用vue.js进行原生开发如何进行Class绑定9. centos6.5 - mysql 连接1006010. 如何把3个不同的MySQL数据库数据整合到一个MySQL数据库中?
