繁体   English   中英

如何将 Internet Explorer 10 支持添加到简单的 VueJs 组件?

[英]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;
             }

          }

       }
    });

我尝试过的故障排除步骤:

  • 使用 babel,虽然我的代码最初不是那样写的。
  • 我使用了 babel-polyfill - 似乎没有效果。
  • 我尝试将正文中脚本标记中的 js 放入主 JS 文件中,以查看在 HTML 中的代码之前加载的 js 文件是否存在问题。 没有效果。

认为可能导致问题的原因: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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM