zoukankan      html  css  js  c++  java
  • js vue 请求

    1. Vue 的 GET 请求
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    var vm = new Vue({ el: '#app', data: { resp: {}, api_url: '/index', }, methods: { get_data(){ this.$http.get(this.api_url) .then((response) => { // 用 set 将响应结果赋给变量 resp this.$set(this.resp,'data',response.body) }).catch(function(response){console.log(response)}) } } }) 2. Vue 的 POST 请求 var vm = new Vue({ el: '#app', data: { resp: {}, post_data: {'name':'abc'}, api_url: '/index', }, methods: { get_data(){ this.$http.post(this.api_url,this.post_data,{emulateJSON:true}) .then((response) => {this.$set(this.resp,'data',response.body)}) .catch(function(response){console.log(response)}) } } })  axios .post('https://www.runoob.com/try/ajax/json_demo.json',{id:id})

    .then(function (response) { console.log(response); }) .catch(function (error) { // 请求失败处理 console.log(error); });
    3. jQuery 的 GET 请求 $(function(){ $("#btn").click(function(){ $.ajax({ url:"/index", dataType:"json", data:{name:'abc'}, type:"get", success:function(resp){ var result result = JSON.parse(resp); } }) }) }) 4. jQuery 的 POST 请求 $("btn").click(function(){ $.post(url,{user:'abc',pwd:'******'},function(resp){ if(resp.success){ $.messager.alert("系统提示","添加成功","info"); }else{ $.messager.alert("系统提示","添加失败","error"); } },"json"); }
  • 相关阅读:
    Uniapp实现微信小程序云开发
    laravel 打印日志
    windbg 学习笔记
    Spring事务,非事务方法调用事务方法,事务不生效
    MyBatis 流式查询
    写代码有这16个好习惯,可以减少80%非业务的bug
    IDEA 神级插件推荐
    OUTLOOK添加企业邮箱
    Win10环境中MATLAB R2020b安装及破解全过程讲解
    scala function vs method
  • 原文地址:https://www.cnblogs.com/LiuFengH/p/10657462.html
Copyright © 2011-2022 走看看