日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue使用axios并存数据到state

發布時間:2023/12/10 vue 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue使用axios并存数据到state 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

npm安裝

npm install axios --save

main.js導入

// 引入axios,并加到原型鏈中 import Axios from 'axios' import QS from 'qs' Vue.prototype.$axios = Axios Vue.prototype.qs = QS

各子模塊中使用,通過原型鏈 this.$axios ......

get實例

<div id="app"><h1>網站列表</h1><divv-for="site in info">{{ site.name }}</div> </div> <script type = "text/javascript"> new Vue({el: '#app',data () {return {info: null}},mounted () {axios.get('https://www.xxxx.com/try/ajax/json_demo.json').then(response => (this.info = response.data.sites)).catch(function (error) { // 請求失敗處理console.log(error);});} }) </script>

post實例

<script> new Vue({el: '#app',data () {return {info: null}},mounted () {axios.post('https://www.xxxxx.com/try/ajax/demo_axios_post.php', {firstName: 'Fred', // 參數 firstNamelastName: 'Flintstone' // 參數 lastName}).then(response => (this.info = response)).catch(function (error) { // 請求失敗處理console.log(error);});} }) </script>

執行多個并發請求

function getUserAccount() {return axios.get('/user/12345'); }function getUserPermissions() {return axios.get('/user/12345/permissions'); } axios.all([getUserAccount(), getUserPermissions()]).then(axios.spread(function (acct, perms) {// 兩個請求現在都執行完成}));

axios API

axios(config) // 發送 POST 請求 axios({method: 'post',url: '/user/12345',data: {firstName: 'Fred',lastName: 'Flintstone'} }); // GET 請求遠程圖片 axios({method:'get',url:'http://bit.ly/2mTM3nY',responseType:'stream' }).then(function(response) {response.data.pipe(fs.createWriteStream('ada_lovelace.jpg')) }); axios(url[, config]) // 發送 GET 請求(默認的方法) axios('/user/12345');

?

總結

以上是生活随笔為你收集整理的vue使用axios并存数据到state的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。