首页 > 解决方案 > 为什么在 Vue.js 中使用 `var` 关键字?

问题描述

我在学习框架时看到的每个教程和代码片段都var用于它们的声明,包括官方文档

前言,我刚开始学习Vue,所以对它了解的很少,但还没有找到答案。

与其他假设属性名称相同:

new Vue({
  data: data
})

对比

new Vue({
  data
})

假设 ES6应该是标准的const,我错了吗?let有理由使用varVue.js 吗?ES6 有问题吗?

标签: javascriptvue.js

解决方案


Why do the docs use var and avoid ES6 features? I'd say to support lowest common denominator, ie, worst browser.

Since Vue can be included as a plain old <script> tag (UMD / global, no build system) and supports all ES5-compliant browsers (IE9+), they keep the documentation consistent.


Use whatever you...

  1. Feel comfortable using, and
  2. Is supported by the target production environment
    • your build system (if you're using one) can help transpile ES6 code to a lower language level

推荐阅读