我正在构建一个简单的VueJs组件,该组件根本无法在IE 10中呈现。
背景:vue组件是公司事件的列表,它支持基本的筛选和排序。不幸的是,我必须支持IE10。我没有使用babel,但尝试将其用于解决此问题-无效
我遇到的错误是'city' is undefined
。 IE10是唯一遇到此问题的浏览器。
这里是仅相关代码的代码笔。我添加了评论以澄清正在发生的事情。 https://codepen.io/thewebtech/pen/zJbeVy
这里只是JS(有关完整代码和更好的上下文,请参见codepen):
/* Server rendered data */
var events = [{
path: "events/residuals-biosolids",
name: "Residuals & Biosolids Conference",
sortDate: "1536165900000",
startDate: "4 September 2018",
endDate: "5 October 2018",
displayDate: "September 4 - October 5, 2018",
state: "WI",
city: "Milwaukee",
booth: "342",
featuredImg: "https://cdn2.hubspot.net/hubfs/4299619/event%20thumb.png"
}, {
path: "events/bio-expo",
name: "Biosolid Expo",
sortDate: "1548979200000",
startDate: "6 February 2019",
endDate: "5 March 2019",
displayDate: "February 6 - March 5, 2019",
state: "MN",
city: "Eagan",
booth: "12",
featuredImg: ""
}, {
path: "events/world-ag-expo",
name: "World AG Expo",
sortDate: "1549670400000",
startDate: "7 February 2019",
endDate: "2 February 2019",
displayDate: "February 7 - 2, 2019",
state: "CA",
city: "Tulare",
booth: "3815",
featuredImg: ""
}];
var eventsDesc = [{
path: "world-ag-expo",
name: "World AG Expo",
sortDate: "1549670400000",
startDate: "7 February 2019",
endDate: "2 February 2019",
displayDate: "February 7 - 2, 2019",
state: "CA",
city: "Tulare",
booth: "3815",
featuredImg: ""
}, {
path: "bio-expo",
name: "Biosolid Expo",
sortDate: "1548979200000",
startDate: "6 February 2019",
endDate: "5 March 2019",
displayDate: "February 6 - March 5, 2019",
state: "MN",
city: "Eagan",
booth: "12",
featuredImg: ""
}, {
path: "residuals-biosolids",
name: "Residuals & Biosolids Conference",
sortDate: "1536165900000",
startDate: "4 September 2018",
endDate: "5 October 2018",
displayDate: "September 4 - October 5, 2018",
state: "WI",
city: "Milwaukee",
booth: "342",
featuredImg: "https://cdn2.hubspot.net/hub/4299619/hubfs/event%20thumb.png?width=760&name=event%20thumb.png"
}];
var selectedStates = ["CA", "MN", "WI", ];
var selectedCities = ["Eagan", "Milwaukee", "Tulare", ];
/*
Vue code below
*/
var app = new Vue({
el: "#sg-events-wrapper",
data: {
message: "Hello Vue!",
dateOrder: "ascending",
selectedCity:"none",
selectedState:"none",
/*the data below is pulled from the script tag in the page.*/
eventCities:selectedCities,
eventStates:selectedStates,
eventList: events,
eventListDesc:eventsDesc,
},
computed: {
eventsSorted:function(){
/*chooses which server generated list to use for rendering events*/
if(this.dateOrder=="ascending"){
return this.eventList;
}
else{
return this.eventListDesc;
}
},
},
methods:{
/*handles the visual filtering when someone sets city and or state*/
isInStateAndCity:function(eventsCity,eventsState){
var citiesMatch;
var statesMatch;
if(eventsCity == this.selectedCity || this.selectedCity=="none"){
citiesMatch = true;
}else{
citiesMatch = false;
}
if(eventsState == this.selectedState ||this.selectedState=="none"){
statesMatch = true;
}else{
statesMatch = false;
}
if(citiesMatch && statesMatch){
return true;
}else{
return false;
}
}
}
});
我尝试过的故障排除步骤:
我认为的原因可能是该问题:
IE 10控制台错误和Codepen渲染失败(如果有帮助的话)的屏幕截图。
如果您有任何想法但又没有测试的方法我可以测试任何更改,然后将我看到的内容和控制台的记录发回记录,如果有错误。
如果需要,我愿意以其他方式对此进行编码。 我真的很感谢任何人愿意提供的帮助。我不认为自己是JavaScript专家,也不是Vue专家。如果您看到我正在做的事情很容易引起问题,请指出来,只是建设性。 “那样做糟透了!”除了YouTube评论垃圾邮件已泄漏到stackoverflow之外,它什么也没教给我。
谢谢!
答案 0 :(得分:1)
我自己发布答案,其他人也可能会遇到此问题,并且那里没有太多信息。
有两个问题。我的selectedCities和selectedStates数组最后有一个逗号。较新的浏览器不在乎,但是<= IE10会。
此外,还有VueJS问题。有人更新了Vue JS,以使用IE 10及更低版本不理解的新正则表达式字符串。解决方法是使用旧版本的VueJS或替换正则表达式。我在哪里找到此信息的说明:
https://github.com/vuejs/vue/issues/7946#issuecomment-393713941
感谢所有提供帮助的人。
特别感谢Pete Emerson和Kevin Leonard(他们通过HubSpot Dev Slack帮助我,发现了根本问题)!