网站显示错误 SCRIPT1003: Expected ':' in IE 11
Website display an error SCRIPT1003: Expected ':' in IE 11
我在一个网站中使用了 vue js 2,结果发现在早期版本的 Internet Explorer 中存在一些兼容性问题。
错误是
SCRIPT1003: Expected ':'
这是代码
methods: {
dataLoaded() {
var ctx = this;
if (window.location.hash) {
var fragmentData = window.location.hash
.replace("#", ""),
.split("/");
var categoryId = fragmentData[0];
var categoryIndex = null;
var offerIndex = parseInt(fragmentData[1]);
var category = this.categories.filter(function(category, index) {
if (category.id == categoryId) categoryIndex = index;
return category.id == categoryId;
})[0];
if (category) {
if (!category.loaded) {
this.loadOffers(category, function() {
if (category.offers[offerIndex]) {
ctx.showDetails(
category.offers[offerIndex],
categoryIndex,
offerIndex
);
}
});
} else if (category.offers[offerIndex]) {
this.showDetails(
category.offers[offerIndex],
categoryIndex,
offerIndex
);
}
}
}
},
IE11 不支持 method definition shorthand syntax 495。您需要使用 babel 作为转译器或将 dataloaded 挂钩更改为 dataLoaded(): function() { //... }
我在一个网站中使用了 vue js 2,结果发现在早期版本的 Internet Explorer 中存在一些兼容性问题。
错误是
SCRIPT1003: Expected ':'
这是代码
methods: {
dataLoaded() {
var ctx = this;
if (window.location.hash) {
var fragmentData = window.location.hash
.replace("#", ""),
.split("/");
var categoryId = fragmentData[0];
var categoryIndex = null;
var offerIndex = parseInt(fragmentData[1]);
var category = this.categories.filter(function(category, index) {
if (category.id == categoryId) categoryIndex = index;
return category.id == categoryId;
})[0];
if (category) {
if (!category.loaded) {
this.loadOffers(category, function() {
if (category.offers[offerIndex]) {
ctx.showDetails(
category.offers[offerIndex],
categoryIndex,
offerIndex
);
}
});
} else if (category.offers[offerIndex]) {
this.showDetails(
category.offers[offerIndex],
categoryIndex,
offerIndex
);
}
}
}
},
IE11 不支持 method definition shorthand syntax 495。您需要使用 babel 作为转译器或将 dataloaded 挂钩更改为 dataLoaded(): function() { //... }