简体   繁体   English

IE 浏览器中的反应性问题

[英]Reactivity issue in IE browser

There is data that I receive from the server every 10 seconds in the Vuex repository:我在 Vuex 存储库中每 10 秒从服务器接收一次数据:

From it I pull the data into the inside of the component through the calculated property:从中我通过计算属性将数据拉入组件内部:

 computed: {

    trackingStatusId: function () {
      return this.$store.state.tracking.trackingServerData.tracking_status_id;
    },
  },

Next, I try to work with this data inside the method: And the method itself is attached to the styles in the html block( <i class="state" :style="getIndicatorWidth()"></i> )接下来,我尝试在方法内部使用这些数据:并且方法本身附加到 html 块中的样式( <i class="state" :style="getIndicatorWidth()"></i>

  methods: {

    getIndicatorWidth: function () {

      function widthCalculate(currentTrackingStatusId){

        console.log(currentTrackingStatusId);

      }

      return widthCalculate(this.trackingStatusId);

    },
  },

Now we pay attention to this line in the above code:现在我们注意上面代码中的这一行:

console.log(currentTrackingStatusId);

If I get changed data from the server, then the value inside the console log changes reactively in all browsers except IE-11 (and below).如果我从服务器获取更改的数据,则控制台日志中的值在除 IE-11(及更低版本)之外的所有浏览器中都会发生反应性更改。

Getting data from the server is as follows: (hung on a lifecycle hook mounted () )从服务器获取数据如下:(挂在一个生命周期钩mounted ()

methods: {

    getTrackerIntervalData () {

        setInterval(()=>myTimer(this), 5000);

        function myTimer(th) {
             return axios.get("https://seo-gmbh.eu/couriertracker/json/couriertracker_api.php?action=get_tracking_data&key_id=" + th.$route.params.tracking.toLowerCase() , {
             })
            .then(response => {
              th.$store.commit('tracking/setTrackingServerData', response.data.data.tracking_data);
            })
            .catch(function (error) {
              console.log(error);
            });
        }
    },
  }



Vuex repository: Vuex 存储库:

const axios = require("axios"); const axios = require("axios");

export const state = () => ({

    trackingServerData: null,

});

export const mutations = {

    setTrackingServerData (state, trackingServerData) {
        state.trackingServerData = trackingServerData;
    },
};



I also duplicate the first request from middleware to be able to work with data when rendering a DOM tree:我还复制了来自中间件的第一个请求,以便在渲染 DOM 树时能够处理数据:

export default function ({$axios, req, store, route}) {导出默认函数 ({$axios, req, store, route}) {

  if(req != undefined) {
      store.commit('setIsFirstServerLoad', true);
  }

  else{
      store.commit('setIsFirstServerLoad', false);
  }

  if(route.name == "language-tracker-tracking") {

      return $axios.get("https://seo-gmbh.eu/couriertracker/json/couriertracker_api.php?action=get_tracking_data&key_id=" + route.params.tracking.toLowerCase(), {})
          .then(response => {
              store.commit('tracking/setTrackingServerData', response.data.data.tracking_data);
          })
          .catch(function (error) {
              console.log(error);
          });

  }

}

As a result, if you look at the situation deeper, it turns out that the IE browser correctly calculates only the code received from middleware:结果,如果您更深入地查看情况,就会发现 IE 浏览器仅正确计算了从中间件接收到的代码:

введите сюда описание изображения

in the above screenshot, you can observe that the answer 8 - is correct - and the answer 3 is generally not clear where it came from.在上面的屏幕截图中,您可以观察到答案 8 - 是正确的 - 而答案 3 通常不清楚它来自哪里。 (maybe even from the last page from the repository - although I had a separate repository for it there. I have no idea why this happens.) (甚至可能来自存储库的最后一页 - 尽管我在那里有一个单独的存储库。我不知道为什么会发生这种情况。)

Question:题:

Why data is not updated correctly in IE browsers?为什么在 IE 浏览器中数据没有正确更新?
How can this be fixed or is it possible to get around this problem - to implement everything differently?如何解决这个问题,或者是否有可能解决这个问题 - 以不同的方式实施一切?

the problem is here问题就在这里

getTrackerIntervalData () {

        setInterval(()=>myTimer(this), 5000);

        function myTimer(th) {
             return axios.get("https://seo-gmbh.eu/couriertracker/json/couriertracker_api.php?action=get_tracking_data&key_id=" + th.$route.params.tracking.toLowerCase() , {
             })
            .then(response => {
              th.$store.commit('tracking/setTrackingServerData', response.data.data.tracking_data);
            })
            .catch(function (error) {
              console.log(error);
            });
        }
    }

IE dosent support arrow function. IE 不支持箭头功能。 you should do it like so你应该这样做

getTrackerIntervalData () {
let vm=this;
        setInterval(function(){myTimer(vm)}, 5000);

        function myTimer(th) {
             return axios.get("https://seo-gmbh.eu/couriertracker/json/couriertracker_api.php?action=get_tracking_data&key_id=" + th.$route.params.tracking.toLowerCase() , {
             })
            .then(response => {
              th.$store.commit('tracking/setTrackingServerData', response.data.data.tracking_data);
            })
            .catch(function (error) {
              console.log(error);
            });
        }
    }

because vue use webpack.因为 vue 使用 webpack。 normally arrow function will be transform to normal function to support all browsers but maybe for some reason the setInterval with arrow function not transform.通常箭头函数将转换为普通函数以支持所有浏览器,但可能出于某种原因,带有箭头函数的setInterval不会转换。 try it maybe that the problem试试吧,也许是问题所在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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