zoukankan      html  css  js  c++  java
  • axios安装及使用

    使用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[0]
        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 === 204) {
              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 === 204) {
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                })
                this.getgjtype('vue') // 重新加载数据
                this.reload() // 刷新页面
                // location.reload()// 刷新页面
                // this.$router.go(0)
              } else {
                this.open4()
              }
            }).catch(console.error.bind(console)) // 异常
  • 相关阅读:
    MySQL和B树的那些事
    记一次临时抱佛脚的性能压测经历
    zookeeper api
    zookeeper笔记
    Mysql优化系列(1)--Innodb重要参数优化
    搞懂MySQL InnoDB B+树索引
    我以为我对Mysql索引很了解,直到我遇到了阿里的面试官
    HDFS原理概念扫盲
    设计原则
    设计模式 6大则
  • 原文地址:https://www.cnblogs.com/ouyangkai/p/11713271.html
Copyright © 2011-2022 走看看