A Pen by Tsuifei Pommier on CodePen.
Created
September 24, 2020 12:43
-
-
Save tsuifei/5f84adfa2600696f4eba9c89a97cf4e4 to your computer and use it in GitHub Desktop.
API_axios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="button" value="get請求" class="get" /> | |
<input type="button" value="post請求" class="post" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let btnGet = document.querySelector(".get"); | |
// 每次取三條笑話 | |
// var urlGet="https://autumnfish.cn/api/joke/list?num=3"; | |
// btnGet.click("getJokes") | |
// const testJokes = function(){ | |
// axios.get(urlGet) | |
// .then(response=>console.log(response)) | |
// .catch(error =>console.log(error)) | |
// } | |
// testJokes() | |
var urlGet2="https://autumnfish.cn/api/joke/list?num=3"; | |
// let data = []; | |
function testJokes2(){ | |
axios.get(urlGet2) | |
.then((res)=>{ | |
console.log(res) | |
data = res.data.num | |
console.log(data) | |
}) | |
} | |
testJokes2() | |
//用戶註冊 API | |
// let btnPost = document.querySelector(".post"); | |
// const urlPost="https://autumnfish.cn/api/user/reg"; | |
// // btnPost.click(testUser) | |
// const testUser = function(){ | |
// axios.post(urlPost,{username:'巴黎SSSSSSSSSS'}) | |
// .then(response=>console.log(response)) | |
// .cache(error => console.log(error)) | |
// } | |
// testUser() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.20.0/axios.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment