欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue?axios中的get請求方式

 更新時間:2022年07月02日 10:37:57   作者:山竹回家了  
這篇文章主要介紹了vue?axios中的get請求方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

vue axios中的get請求

一、安裝

使用 npm:npm install axios

二、使用

步驟:1.引入 2.發(fā)送請求

<template>
? <div>
? ? <!-- 2.點擊發(fā)送請求 -->
? ? <button @click="getdata">get請求-無參數(shù)</button
? ? ><button @click="getDataByParams">get請求-有參數(shù)</button>
? </div>
</template>
<script>
//1.引入axios
import axios from "axios";
export default {
? methods: {
? ? // 3.發(fā)送axios無參數(shù)請求
? ? getdata() {
? ? ? axios
? ? ? ? // 3.1url地址
? ? ? ? .get("http://157.122.54.189:9095/scenics/banners")
? ? ? ? // 3.2成功時回調(diào)函數(shù)
? ? ? ? .then((data) => {
? ? ? ? ? console.log(data);
? ? ? ? })
? ? ? ? //3.3失敗時回調(diào)函數(shù)
? ? ? ? .catch((err) => {
? ? ? ? ? console.log(err);
? ? ? ? });
? ? },
? ? // 有參數(shù)
? ? getDataByParams() {
? ? ? axios
? ? ? ? //params:可傳遞多個參數(shù),固定寫法,不能改,否則參數(shù)傳遞失敗
? ? ? ? .get("http://157.122.54.189:9095/posts", { params: { id: 4 } })
? ? ? ? .then((data) => {
? ? ? ? ? console.log(data);
? ? ? ? })
? ? ? ? .catch((err) => {
? ? ? ? ? console.log(err);
? ? ? ? });
? ? },
? },
};
</script>
<style>
</style>

常見錯誤

url后面不要寫冒號,否則會結(jié)束。 

vue axios post請求參數(shù)錯誤400

如果直接把loginMode1當請求參數(shù)傳,后端是接收不到的

要對loginMode1處理成字符串然后再轉(zhuǎn)換,如下

然后再axios處理

這樣就不會有問題了

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論