【发布时间】:2020-01-19 09:03:17
【问题描述】:
使用 Vue 组件文件,我从 JSON API 获取一条记录并在模板中显示该记录数据,但它仅适用于重新加载页面。我正在使用 axios 和 v-bind 来获取和显示模板中的数据。
我尝试在脚本部分设置 cache: false 但我不确定这是否是我需要做的或如何做。
我需要设置或禁用某种类型的缓存设置吗?
<div id="PatientList" class="container">
<div>
<h3 class="heading" style="text-align:left">ID {{$route.params.id}}</h3>
<input id="lens" v-model= "search" placeholder ="Search here">
<br><br>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Mobile</th>
<th scope="col">Email</th>
</tr>
</thead>
<tbody>
<tr v-bind:key="patient">
<td>{{ patient.id }}</td>
<td>{{ patient.first_name + " " + patient.last_name }}</td>
<td>{{ patient.mobile }}</td>
<td>{{ patient.email }}</td>
<td>></td>
</tr>
</tbody>
</table>
</div>
</template>
<script>
import axios from "axios";
export default {
name: 'PatientList',
data () {
return {
patient: '',
}
},
mounted () {
axios
.get('http://localhost:8000/Patients/'+ this.$route.params.id +'/?format=json')
.then(response => (this.patient = response.data))
.catch(error => console.log(error))
},
}
</script>
<style>
#app {
text-align: center;
margin-top: 50px;
}
.heading {
margin-bottom: 30px;
}
#lens {
position: relative;
left: -468px;
}
</style>```
【问题讨论】:
-
在使用相同组件的路由之间导航时是否出现问题?所以只是
id正在改变? -
当它第一次在路线上加载时,它工作正常,当更改路线时,只有 ID 发生变化,并且在重新加载完成之前不会更新值。