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);
        });

这样写好像毫无反应,也没有回报.看文档貌似也没有例子
this.$ajax 在vue的main.js配置过了

阅读 20.4k
5 个回答
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);
});

axios说实话我没见过你所写的methods这个属性

delete应该是axios的一个方法

你应该axios.delete(url).then(res=>{}) 这种格式

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

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()
新手上路,请多包涵
axios
        .delete(`http://localhost:3000/heroes/${id}`)
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        });

可以这样写

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题