本文首发于我的个人博客
本篇文章记录了作者在使用Vue+Axios实现前端自动刷新数据时,遇到的一个坑点。
场景需求
在一个Vue单页应用中,使用VueRouter实现了App组件中点击链接后呈现Component组件的功能
App.Vue -> Component.Vue
现在需要:在Component加载出来之后,每间隔1s的时间,自动通过Axios向后端接口获取数据并更新。
有问题的实现方式
App.Vue,内置router-link,可以跳转呈现Component
// App.Vue
<template>
<div>
<router-link :to="/Component">Component</router-link>
<router-view></router-view>