[英]How do I add Internet Explorer 10 support to a simple VueJs component?
我正在構建一個簡單的 VueJs 組件,它在 IE 10 中根本不呈現。
背景:Vue 組件是公司事件的列表,支持基本的過濾和排序。 不幸的是,我必須支持IE10。 我沒有使用 babel,但試圖用它來解決這個問題 - 沒有效果
我得到的錯誤是'city' is undefined
。 IE10 是唯一遇到此問題的瀏覽器。
這是僅相關代碼的 CodePen 。 我添加了評論以澄清正在發生的事情。 這里只是 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;
}
}
}
});
我嘗試過的故障排除步驟:
我認為可能導致問題的原因:IE10 不喜歡像我正在做的那樣為對象分配屬性值。 不確定這一點。 這只是一個猜測,我想不出另一種方法來做到這一點。
IE 10 控制台錯誤和 CodePen 中渲染失敗的屏幕截圖,以防萬一。
如果您有任何想法但沒有測試方法:我可以測試任何更改並發送我所看到的記錄和控制台(如果有錯誤)。
自己發布答案,因為其他人也可能會遇到這個問題,並且沒有太多信息。
有兩個問題。 我的 selectedCities 和 selectedStates 數組的末尾有一個逗號。 較新的瀏覽器不關心這一點,但 <=IE10 關心。
此外還有一個 VueJS 問題。 有人更新了 Vue JS 以使用 IE 10 及以下版本不理解的新正則表達式字符串。 解決方法是使用舊版本的 VueJS 或替換正則表達式。 我找到此信息的來源的說明:
https://github.com/vuejs/vue/issues/7946#issuecomment-393713941
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.