鍍金池/ 問答/HTML/ axios的delete方法怎么寫

axios的delete方法怎么寫

this.$ajax({
          method: 'delete',
          url: '/api/commodityCategory/delete',
          data: {
            "id":"a"
          },
        })
        .then(function(response) {
          console.log(response);
        })
        .catch(function(response) {
          console.log(response);
        });

這樣寫好像毫無反應(yīng),也沒有回報(bào).看文檔貌似也沒有例子
this.$ajax 在vue的main.js配置過了

回答
編輯回答
久礙你

axios說實(shí)話我沒見過你所寫的methods這個屬性

delete應(yīng)該是axios的一個方法

你應(yīng)該axios.delete(url).then(res=>{}) 這種格式

2017年7月19日 04:02
編輯回答
影魅

request<T = any>(config: AxiosRequestConfig): AxiosPromise<T>;
get<T = any>(url: string, config?: AxiosRequestConfig): AxiosPromise<T>;
delete(url: string, config?: AxiosRequestConfig): AxiosPromise;
head(url: string, config?: AxiosRequestConfig): AxiosPromise;
post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
put<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;
patch<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;

delete是要傳config的
config中放data

export interface AxiosRequestConfig {
url?: string;
method?: string;
baseURL?: string;
transformRequest?: AxiosTransformer | AxiosTransformer[];
transformResponse?: AxiosTransformer | AxiosTransformer[];
headers?: any;
params?: any;
paramsSerializer?: (params: any) => string;
data?: any;
timeout?: number;
withCredentials?: boolean;
adapter?: AxiosAdapter;
auth?: AxiosBasicCredentials;
responseType?: string;
xsrfCookieName?: string;
xsrfHeaderName?: string;
onUploadProgress?: (progressEvent: any) => void;
onDownloadProgress?: (progressEvent: any) => void;
maxContentLength?: number;
validateStatus?: (status: number) => boolean;
maxRedirects?: number;
httpAgent?: any;
httpsAgent?: any;
proxy?: AxiosProxyConfig;
cancelToken?: CancelToken;
}

然后就寫成這樣
export const elete= config => { return axios.delete(url, config).then(res => res.data) }
delete({

      data: {
        vin: this.delVin
      }
    }).then().catch()
2018年7月18日 19:44
編輯回答
熊出沒

this.$ajax.detele('/api/commodityCategory/delete',{id:'a'}).then(res=>{})

2017年12月18日 11:42
編輯回答
愿如初
axios
        .delete(`http://localhost:3000/heroes/${id}`)
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });

可以這樣寫

2017年10月6日 15:20
編輯回答
尐飯團(tuán)
axios.delete({
  url: '/api/commodityCategory/delete',
  data: {
    "id":"a"
  }
})
.then(function(response) {
  console.log(response);
})
.catch(function(response) {
  console.log(response);
});

或者:

axios({
  method: 'delete',
  url: '/api/commodityCategory/delete',
  data: {
    "id":"a"
  }
})
.then(function(response) {
  console.log(response);
})
.catch(function(response) {
  console.log(response);
});
2017年1月8日 15:56