我试着把下面的代码转到试试看标签上-
class aboutController{
constructor(ajaxService){
this.ajaxService = ajaxService;
this.printLog();
}
printLog(){
this.ajaxService.log();
}
static $inject = ["ajaxService"];
}静态关键字被转换为
{
key: "$inject",
value: ["ajaxService"],
enumerable: true
}然后,我尝试了咕噜-巴贝尔任务,以自动化的构建。我的gruntfile.js是这样的-
module.exports = function(grunt){
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
babel: {
options: {
sourceMap: true,
highlightCode: true
},
es6: {
files: [
{
expand: true,
src: ['components/**/*.es6'],
ext: '.js'
}
]
}
},
watch: {
scripts: {
files: ['components/**/*.es6'],
tasks:['babel']
}
}
});
require("load-grunt-tasks")(grunt);
grunt.registerTask("default", ["babel", "watch"]);
}但是现在静态关键字给出了错误,当我移除静态关键字时,构建正在传递。知道怎么解决这个问题吗。咕噜-巴贝尔过时了吗?
我的packahe.json是这样的-
{
"name": "babeles6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "~0.4.2",
"grunt-babel": "^5.0.1",
"grunt-contrib-watch": "^0.6.1",
"load-grunt-tasks": "^3.2.0"
}
}发布于 2015-09-06 06:25:53
ES6类语法只支持方法。您的示例使用ES7-建议的类属性。如果您检查了“实验”,则在Babel中启用“试试看”。
static $inject = ["ajaxService"];只有当您专门启用es7.classProperties或广泛启用所有阶段0转换时,才能工作。
与ES6兼容的方法将是
static get $inject(){
return ["ajaxService"];
}https://stackoverflow.com/questions/32420634
复制相似问题