vue使用request.get请求后端之后不自动刷新页面
时间: 2023-08-14 09:05:06 浏览: 137
在 Vue 中,可以使用 `axios` 库发送 `GET` 请求,不会导致页面自动刷新。具体步骤如下:
1. 安装 `axios` 库,可以使用 `npm` 或者 `yarn` 安装。
```shell
npm install axios
```
2. 在 Vue 组件中引入 `axios` 库并发送 `GET` 请求。
```javascript
import axios from 'axios';
export default {
data() {
return {
data: null
};
},
mounted() {
axios.get('/api/data')
.then(response => {
this.data = response.data;
})
.catch(error => {
console.log(error);
});
}
}
```
3. 在模板中使用 Vue 的数据绑定功能来更新页面上的部分内容。
```html
<template>
<div>
<p>{{ data }}</p>
</div>
</template>
```
这样就可以在 Vue 中使用 `axios` 发送 `GET` 请求,并获取后端数据,而不会自动刷新整个页面。
阅读全文
相关推荐















