vue 向服务器端 发起 Get 和 Post 请求 及 $axios方式请求

Get

onSelect() { 
      var url = 'http://192.168.1.143:5011/httpCli?action=query'+"&name="+this.selectForm.name+"&phone="+this.selectForm.phone ;
      this.$http.get(url).then((result) => {
        console.log(result);
        console.log(result.data);

      }).catch((err) => {
        console.log(err)
      })
 
},
$axios 方式
      //api请求
      this.$axios({
        url: '/sina/api/channels'+'/'+uuid,
        method:'DELETE',
        //发送格式为json
        data:'',  //自己的uuid
        headers:{
          'Content-Type': 'application/json',
          'X-XTRA-AUTH-ID': this.$store.state.current_call_token  } //token
      })
      .then(function(response){
        console.log(response);
        let { result, message } = response.data;//解析JSON
        //console.log("result:"+result +"  " + "message:"+message);  
        var msg="";
        if(result='success')
        { msg="保存 "+ext_tel +" 成功!"; }
        else
        { msg="保存 "+ext_tel +" 失败! "+ result +"  " +message; }
        this.$message({
            message: msg,
            type: 'success'
        });

      }.bind(this))
      .catch(function (error) {
        console.log(error);
      });
      //--------------------------------------------------------------
   

 

posted @ 2022-07-07 11:11  海乐学习  阅读(241)  评论(0编辑  收藏  举报