使用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)) // 异常

最新文章

  1. ASP.NET MVC之视图生成URL(二)
  2. IOS Animation-贝塞尔曲线与Layer简单篇(一)
  3. anroid开发者专用vpn
  4. POD数据了解
  5. WebService简单介绍
  6. margin负值的使用
  7. Nginx高性能服务器安装、配置、运维 (3) —— Nginx配置详解
  8. SQL Server 内存开销分析
  9. 从控制台读取password - C#
  10. http://codeforces.com/contest/610/problem/D
  11. idea Code激活
  12. PHP实现WebService的简单示例和实现步骤
  13. CF AIM Tech Round 3 (Div. 2) D - Recover the String
  14. Java8-如何构建一个Stream
  15. JAVA 调用exe程序执行对应的文件 (个人用于编译Java文件)
  16. [BZOJ 4152][AMPPZ 2014]The Captain
  17. Paypal2017实习生-软件开发-B卷
  18. 1)django-建立步骤和目录说明
  19. MYSQL 内存模型
  20. QQ群管理员申请帖(本次截止日期为2017-03-25)

热门文章

  1. C语言杂
  2. Confluence 6.9.0 安装
  3. 经典的卷积神经网络及其Pytorch代码实现
  4. Rust中的控制结构
  5. Nginx 初步认识
  6. Java虚拟机所管理的内存,包含的运行时数据区域?
  7. swarm 集群
  8. Node.js到底是做什么的?这是我看到最好的解释了
  9. 团队冲刺---Four
  10. WebSocket协议-基础篇