zoukankan      html  css  js  c++  java
  • VUE 3 使用 axios 麦克斯

    <script lang="ts">
    import {defineComponent} from 'vue';//导入defineComponent函数可以对使用$data调用data里的变量
    import axios from "axios";//导入axios 可直接使用axios 
    export default defineComponent({
    
      data() {
        return {
          unit: '',
        }
      },
    
      name: 'Home',
    
      methods: {
    
        save:function (){
    
          axios
              .post('http://localhost:8080/units', {
                //变量值必须加this.$data关键字才能正确对应data里面的对象
                unit_name: this.$data.unit, // 参数 unit_name 为后台对应变量名
              })
              .then(function (response) {
                //此处用的写法可保证进行成功回调时能执行其他代码
                if(response.status==201){
                  alert("添加成功");
                }else{
                  alert("添加失败");
                }
    
              })
              .catch(function (error) { // 请求失败处理
                console.log(error);
              });
    
        }
    
        }
    
    });
    
    
    
    
    
    </script>
    

      

  • 相关阅读:
    selenium 难定位元素、时间插件
    列表生成式
    三元表达式
    监控日志
    非空即真
    深拷贝浅拷贝
    元组
    list字典嵌套
    2021
    布尔类型
  • 原文地址:https://www.cnblogs.com/max-hou/p/15755379.html
Copyright © 2011-2022 走看看