久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      vuejs怎么請(qǐng)求攔截

      vuejs請(qǐng)求攔截的方法:1、在src文件夾下創(chuàng)建utils文件夾;2、在文件夾下創(chuàng)建request.js和auth.js文件;3、下載axios;4、創(chuàng)建實(shí)例實(shí)現(xiàn)請(qǐng)求攔截即可。

      vuejs怎么請(qǐng)求攔截

      本文操作環(huán)境:windows7系統(tǒng)、Vue2.9.6版、DELL G3電腦。

      vuejs怎么請(qǐng)求攔截?

      vue數(shù)據(jù)請(qǐng)求攔截的具體代碼

      在src文件夾下創(chuàng)建utils文件夾

      vuejs怎么請(qǐng)求攔截

      同時(shí)在文件夾下創(chuàng)建request.js和auth.js文件

      request.js為請(qǐng)求攔截、請(qǐng)求數(shù)據(jù)封裝主入口
      auth.js為設(shè)置token和刪除token及判斷用戶是否登錄封裝主入口

      auth.js (封裝token)

      export function isLogin() {   if (localStorage.getItem('token')) {    return true;   } else {    return false;   }  }  export function getToken() {   return localStorage.getItem('token');  }  export function setToken(token) {   localStorage.setItem('token', token);  }    export function removeToken() {   localStorage.removeItem('token');  }

      下載axios(命令: npm install axios –save-dev)、同時(shí)引入axios、getToken

      import axios from 'axios'; import { getToken } from './auth';

      創(chuàng)建實(shí)例:傳兩個(gè)參數(shù)(timeout(超時(shí)時(shí)間)、baseUrl(服務(wù)器路徑))

      const instance = axios.create({    timeout: 5000,    baseURL: 'https://xxxxxxxxx/xxxx/',  });

      請(qǐng)求攔截

      // 請(qǐng)求攔截  instance.interceptors.request.use(   function(config) {    // eslint-disable-next-line prettier/prettier    config.headers.authorization = 'Bearer ' + getToken();    return config;   },   function(error) {    // Do something with request error    return Promise.reject(error);   }  );    instance.interceptors.response.use(   response => {    return response;   },   error => {    if (error.response.status == 401) {     window.location.href = '/#/login';    }    if (error.response.status == 404) {     window.location.href = '/404.html';    }    return Promise.reject(error.response.data);   }  );

      請(qǐng)求封裝

       /**   * 獲取數(shù)據(jù) get請(qǐng)求   * @param {*} url   * @param {*} config   */  export const get = (url, config) => instance.get(url, config);    /**   * post請(qǐng)求   * @param {*} url   * @param {*} data   * @param {*} config   */  export const post = (url, data) => instance.post(url, data);  /**   * put   * @param {*} url   * @param {*} data   * @param {*} config   */  export const put = (url, data, config) => instance.put(url, data, config);    /**   * delete   * @param {*} url   * @param {*} config   */  export const remove = (url, config) => instance.delete(url, config);

      推薦學(xué)習(xí):《vue教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)