axios安装及使用
2024-09-08 11:24:24
使用npm安装
$ npm install axios
使用 bower安装
$ bower install axios
使用 cdn:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
main.js:导入
import axios from 'axios'
Vue.prototype.$http = axios
Vue.prototype.$http.defaults.baseURL = '' // `baseURL` 将自动加在 `url` 前面,除非 `url` 是一个绝对 URL
调用接口使用axios:
1: 接口数据读取
querygraphic () {
let _this = this
this.$http.get('https://localhost:44314/api/Values').then(res => {
_this.list = res.data
}) data () {
return {
list: []
} 调用赋值:v-for="queryg in list":key="queryg.id" {{ queryg.version }}
2:按id数据读取
getgrid () { this.$http.get('https://localhost:44314/api/Values/' + this.id).then(res => {
this.gettext = res.data[]
console.log(this.gettext)
}) data () {
return {
id: this.$route.params.id, // 读取路由传过来的id
gettext: {}
}
}, 调用赋值:
{{ gettext.text }}
3:put更新
this.$http({
url: 'https://localhost:44314/api/Gj/' + this.id,
method: 'put',
contentType: 'application/json;charset=UTF-8', data: {
'id': this.newinfo.id,
'method': this.newinfo.method,
'text': this.newinfo.text,
'type': this.newinfo.type
},
dataType: 'json'
}).then(res => {
console.log(res)
if (res.status === ) {
this.open1()
console.log('成功')
} else {
this.open4()
console.log('失败')
}
}).catch(console.error.bind(console)) // 异常
4:delete删除
this.$http.delete('https://localhost:44314/api/Gj/' + row.id).then(res => {
if (res.status === ) {
this.$message({
type: 'success',
message: '删除成功!'
})
this.getgjtype('vue') // 重新加载数据
this.reload() // 刷新页面
// location.reload()// 刷新页面
// this.$router.go(0)
} else {
this.open4()
}
}).catch(console.error.bind(console)) // 异常
最新文章
- ASP.NET MVC之视图生成URL(二)
- IOS Animation-贝塞尔曲线与Layer简单篇(一)
- anroid开发者专用vpn
- POD数据了解
- WebService简单介绍
- margin负值的使用
- Nginx高性能服务器安装、配置、运维 (3) —— Nginx配置详解
- SQL Server 内存开销分析
- 从控制台读取password - C#
- http://codeforces.com/contest/610/problem/D
- idea Code激活
- PHP实现WebService的简单示例和实现步骤
- CF AIM Tech Round 3 (Div. 2) D - Recover the String
- Java8-如何构建一个Stream
- JAVA 调用exe程序执行对应的文件 (个人用于编译Java文件)
- [BZOJ 4152][AMPPZ 2014]The Captain
- Paypal2017实习生-软件开发-B卷
- 1)django-建立步骤和目录说明
- MYSQL 内存模型
- QQ群管理员申请帖(本次截止日期为2017-03-25)