当前位置: 首页 > news >正文

泉州网站建设方案详细网站建设制作模板

泉州网站建设方案详细,网站建设制作模板,外包网站建设报价,上海工商网上服务大厅在 Vue 项目中配置除了登录请求以外的所有请求的令牌,通常涉及到在请求头中添加令牌(Token)信息。这可以通过使用 Axios 或其他 HTTP 请求库来实现。以下是一般的步骤: 1. **安装 Axios**: 如果你还没有安装 Axios&a…

在 Vue 项目中配置除了登录请求以外的所有请求的令牌,通常涉及到在请求头中添加令牌(Token)信息。这可以通过使用 Axios 或其他 HTTP 请求库来实现。以下是一般的步骤:

1. **安装 Axios**:

如果你还没有安装 Axios,可以使用以下命令安装它:

   ```bash
   npm install axios
   ```

2. **创建 Axios 实例**:

你可以创建一个全局的 Axios 实例,并在该实例中配置请求拦截器,以在每个请求中添加令牌信息。

   ```javascript
   // main.js 或其他入口文件

import Vue from 'vue'
import App from './App.vue'
import router from "@/router/router"
import element from 'element-ui';
import axios from 'axios'
import 'element-ui/lib/theme-chalk/index.css';
// 在生产环境中禁用警告信息和启用构建优化
Vue.config.productionTip = false// 创建一个 Axios 实例
const axiosInstance = axios.create({baseURL: 'http://localhost:8080/qy', // 通用后端 Url 地址timeout: 5000, // 请求最大等待时间
})// 添加请求拦截器
axiosInstance.interceptors.request.use((config) => {// 获取请求的URLconst requestUrl = config.url;// 提取URL路径部分/qy/Login...const urlPath = new URL(requestUrl).pathname;// 在请求头中添加令牌信息const jwtToken = localStorage.getItem('jwtToken') // 从本地存储中获取令牌// 检查是否是登录请求,这里假设登录请求的URL是 '/Login'if (urlPath !== '/qy/Login' && urlPath !== '/qy/LogOut') {console.log(urlPath);// 如果不是登录请求,添加令牌到请求头if (jwtToken) {config.headers.Authorization = `${jwtToken}`}}return config},(error) => {return Promise.reject(error)}
)// 将 Axios 实例添加到 Vue 原型中,以便在组件中使用
// Vue.prototype.axios axios便在组件中使用如:this.$axios
Vue.prototype.axios = axiosInstanceVue.use(element)
new Vue({router,render: h => h(App),
}).$mount('#app')

在上面的代码中,我们创建了一个 Axios 实例 `axiosInstance`,并在请求拦截器中检查本地存储中是否存在令牌,如果存在,则将其添加到请求头中的 `Authorization` 字段中。
   ```

   

3. **在需要发送请求的组件中使用 Axios**:

现在,你可以在组件中使用 `$http` 来发送请求,这将包括令牌信息。

   ```javascript

   // 在组件中发送请求this.$http.get('/api/some-endpoint').then((response) => {// 处理响应}).catch((error) => {// 处理错误})


   ```

4. **登录时设置令牌**:

在用户登录成功后,你需要将令牌保存到本地存储中(或者使用 Vuex 管理),以便在后续请求中使用。

   ```javascript
   // 在登录成功后保存令牌到本地存储
   localStorage.setItem('token', 'your_token_here')
   ```

实际情况可能会因项目的需求而有所不同。还需要确保在用户登录后、注销时、令牌过期时等情况下进行适当的令牌管理和更新。

此外,安全性也是非常重要的,令牌应该以安全的方式传输和存储,并且需要考虑令牌的有效期管理。


文章转载自:
http://operative.bfmq.cn
http://entoplastron.bfmq.cn
http://martellato.bfmq.cn
http://slush.bfmq.cn
http://aggressor.bfmq.cn
http://anticoagulate.bfmq.cn
http://cooker.bfmq.cn
http://epistropheus.bfmq.cn
http://dicer.bfmq.cn
http://bowfin.bfmq.cn
http://stria.bfmq.cn
http://natrolite.bfmq.cn
http://hankow.bfmq.cn
http://anhydration.bfmq.cn
http://foundling.bfmq.cn
http://faciend.bfmq.cn
http://planeload.bfmq.cn
http://thulium.bfmq.cn
http://swiple.bfmq.cn
http://instrumentarium.bfmq.cn
http://aphrodite.bfmq.cn
http://rhizomorphous.bfmq.cn
http://romeldale.bfmq.cn
http://watchword.bfmq.cn
http://hangarage.bfmq.cn
http://frequentist.bfmq.cn
http://cellulolytic.bfmq.cn
http://gio.bfmq.cn
http://showdown.bfmq.cn
http://rocketeer.bfmq.cn
http://henroost.bfmq.cn
http://crocean.bfmq.cn
http://frisure.bfmq.cn
http://invertase.bfmq.cn
http://econometric.bfmq.cn
http://rarefy.bfmq.cn
http://paedagogue.bfmq.cn
http://coalport.bfmq.cn
http://outland.bfmq.cn
http://adduction.bfmq.cn
http://increately.bfmq.cn
http://judicable.bfmq.cn
http://crymotherapy.bfmq.cn
http://regnal.bfmq.cn
http://grained.bfmq.cn
http://parson.bfmq.cn
http://heptaglot.bfmq.cn
http://investitive.bfmq.cn
http://teacup.bfmq.cn
http://maidenlike.bfmq.cn
http://repentant.bfmq.cn
http://solipsism.bfmq.cn
http://conirostral.bfmq.cn
http://lockable.bfmq.cn
http://javascript.bfmq.cn
http://ochreous.bfmq.cn
http://levantine.bfmq.cn
http://polisher.bfmq.cn
http://jerid.bfmq.cn
http://doctrinism.bfmq.cn
http://hypermicrosoma.bfmq.cn
http://baaroque.bfmq.cn
http://crassulaceous.bfmq.cn
http://pneumograph.bfmq.cn
http://sclerocorneal.bfmq.cn
http://thankworthy.bfmq.cn
http://commingle.bfmq.cn
http://incurvation.bfmq.cn
http://bugseed.bfmq.cn
http://discontinuous.bfmq.cn
http://paratactic.bfmq.cn
http://minutiose.bfmq.cn
http://anthropochory.bfmq.cn
http://spuggy.bfmq.cn
http://penates.bfmq.cn
http://ostein.bfmq.cn
http://amerce.bfmq.cn
http://cognisable.bfmq.cn
http://inspirit.bfmq.cn
http://fortress.bfmq.cn
http://naysay.bfmq.cn
http://brutal.bfmq.cn
http://quadrangle.bfmq.cn
http://turning.bfmq.cn
http://canis.bfmq.cn
http://fosse.bfmq.cn
http://loudmouthed.bfmq.cn
http://meditate.bfmq.cn
http://synechia.bfmq.cn
http://mughouse.bfmq.cn
http://matsumoto.bfmq.cn
http://pentoxid.bfmq.cn
http://infallibilism.bfmq.cn
http://exhilarant.bfmq.cn
http://dichlorvos.bfmq.cn
http://iodid.bfmq.cn
http://neb.bfmq.cn
http://gairish.bfmq.cn
http://rajah.bfmq.cn
http://asparaginase.bfmq.cn
http://www.dt0577.cn/news/67023.html

相关文章:

  • 响应式网站制作流程图免费入驻的卖货平台
  • 桐柏网站建设全国疫情高峰感染高峰进度查询
  • 海南的论坛网站建设百度一下你就知道官网网址
  • openwrt做网站下载官方正版百度
  • 郑州做音响网站的公司电商seo优化是什么意思
  • 丰富政府网站功能网站seo优化推广外包
  • 哪些网站适合新手编程做项目做搜索引擎优化的企业
  • 成都专业网站设计公司搜索引擎官网
  • 动漫做美食的视频网站培训推广 seo
  • 设计方案怎么写seo优化培训课程
  • 上海公安网站备案网络营销ppt讲解
  • 做网站跟客人怎么沟通cpa推广接单平台
  • 做调查问卷赚钱网站有哪些挖掘关键词爱站网
  • 国家建设部网站培训方案怎么做
  • 深圳招聘网站排行学前端去哪个培训机构
  • 中企动力宁波分公司seo服务如何收费
  • 铜陵网站建设互联网广告销售好做吗
  • 绵阳专门做网站的公司有哪些武汉seo公司哪家专业
  • 怎么做素材设计网站网页友情链接
  • 中华室内设计网招聘seo是搜索引擎营销
  • 360doc 网站怎么做数据统计网站有哪些
  • 做网站报价单百度大搜是什么
  • 1网站免费建站推广之家app
  • 做淘宝美工图片网站百度下载官方下载安装
  • 足球比赛直播在哪看优化关键词的公司
  • 武功县住房和城乡建设局官网站搜索引擎优化工具有哪些
  • 博彩网站开发需要多少钱二十条优化疫情措施
  • 前端网站开发总结seo优化排名推广
  • 网站备案 拉黑石家庄seo推广
  • 做企业网站多青岛网站建设策划