js object attribute names use dash naming method

If you directly use the dash naming method for the object attribute name, an error will be reported. The correct way to write it is as follows:

// 这是正确写法↓
conse obj={
  'r-button': 51,
  'r-form': 42,
  'r-select': 76
}

conse obj={
  r-button: 51,   //这样会报错
  `r-form`: 42,    //这样会报错
  "r-select": 76    //这样不会报错,双引号也可以
}

console.log(obj['r-form'])  // 取用时应该这样写
// console.log(obj.r-form)  // 这样会报错

Guess you like

Origin blog.csdn.net/m0_56683897/article/details/128296550