vue_token
token
<template> <button type="button" @click="getToken">获取token_myapp</button> <button type="button" @click="getToken_heima">获取token_黑马</button> </template> <script setup> import axios from "axios"; import jwttoken from "jwt-decode"; const url = "http://127.0.0.1:8888/api/Login/LoginIn"; const getToken = async () => { axios .get(url, { params: { UId: "zhou", Pwd: "123", }, }) .then((res) => { console.log(res.data); // sessionStorage.token = res.data; // sessionStorage.userInfo = jwttoken(res.data).NickName; }); }; // const url_heima = "/api" + "/login"; const url_heima = "https://lianghj.top:8888/api/private/v1/login"; const getToken_heima = async () => { axios .post(url_heima, { username: "admin", password: "123456", }) .then((res) => { console.log(res.data); // sessionStorage.token = res.data; // sessionStorage.userInfo = jwttoken(res.data).NickName; }); }; </script> <style lang="scss" scoped></style>
// 获取课程信息
const url = "http://127.0.0.1:8888/api/Login/GetList";
const getToken = () => {
axios.defaults.headers.common.Authorization =
"Bearer " + sessionStorage.token;
axios.get(url).then((res) => {
console.log(res.data);
});
};