Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.5k views
in Technique[技术] by (71.8m points)

为啥vue中a标签下载点击一次会加载两次下载的情况(刷新的情况下)

最近发现vue中使用a标签下载有个很诡异的问题,就是刷新之后点击下载会下载两次。然后接着又是下载一次。只要刷新就会下载两次。本地没有这样的情况,发布了就出现这样的情况。有哪位大佬遇到过的吗?留言,感激不尽。

<a  id="outExcelApplyCheckIn">下载</a>
        getList(){
        let params={}
        this.setExcel(params)
          },
       setExcel(params) {
        let outExcelApplyCheckInDom = document.getElementById('outExcelApplyCheckIn');
        let token = this.$store.state.token;
        let searchParamsHref = '';
        let baseHref = `${url.export}?token=${token}`;
        //判断对象是否有值
        if (Object.keys(params).length > 0) {
          for (let i in  params) {
            if (i != 'page' && i != 'size') {
              searchParamsHref += `&${i}=${params[i]}`
            }
          }
        }

       let allHref = baseHref + searchParamsHref;
        outExcelApplyCheckInDom.href = allHref;
      },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

猜测可能的原因是刷新之后,vuex中token被清空了。导致

let baseHref = `${url.export}?token=${token}`;

这句话的地址改变了,所以向服务器又请求了一次。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...