1. トークンを取得してローカルストレージに保存します
this.axios.post('/api/アカウント', {
usernameOrEmailAddress: this.ruleForm.name, //フォームにパラメータを送信します
パスワード: this.ruleForm.pass
})
.then(応答 => {
localStorage.setItem('token', response.data.result);//トークンをlocalStorageに保存します
const token = localStorage.getItem('token');
this.token_infor = トークン
})
.catch(エラー => {
コンソール.ログ(エラー);
});
メソッドの中にメソッドを書く
GetEquipInfor() {
const axiosInstance = axios.create({
ベースURL: ''
});
axiosInstance.defaults.headers.common['Authorization'] = `Bearer ${localStorage.getItem('token')}`//设置トークン
axiosInstance.post('/api/services/app/BaseData/GetEquipments', { 通常どおり投稿リクエストの形式に従ってください
プラントコード: "00001.00001.00009",
ページ1、
サイズ: 20、
注文: []、
フィルター: []
})
.then(応答 => {
console.log(response.data.result.data.records)
this.tableData = 応答.データ.結果.データ.レコード
})
.catch(エラー => {
コンソール.ログ(エラー);
});
}
3. 最後に、必要に応じて、作成したファイルで呼び出します。
作成した() {
this.GetEquipInfor()
}