npm i --save axios
import axios from 'axios' Vue.prototype.axios = axios
3.在項目methods/使用php
Getios
this.axios({ method:'get', url:'test.php', params:{state:"join"}, }).then((response) =>{ console.log(response['data'])//成功數據 }).catch((error) =>{ console.log(error)//錯誤數據 alert(error) }) },
Postnpm
this.axios({ method:'post', url:'test.php', data:data, }).then((response) =>{ console.log(response);//成功數據 }).catch((error) =>{ console.log(error)//錯誤數據 }) },
axios 默認post 是用request payload來傳輸的axios
let data = new FormData() data.append('data1','data1') this.axios({ method:'post', url:'lottery.php', data:data, }).then((response) =>{ console.log(response);//成功數據 }).catch((error) =>{ console.log(error)//錯誤數據 }) },