methods: {
submitForm() {
this.$api
.login({ mobile: "yunfeng", password: "123456" })
.then((res) => {
if (res.status === 200) {
// 在 sessionStorage中设置token,值为后台数据中的token
sessionStorage.setItem('token',res.data.data.token) //重点
this.$store.commit("changeUser", res.data.data);
this.$store.commit("changeFlag", true);
this.$router.push({ name: "order" });
} else {
console.log(res.data.info);
}
})
.catch((data) => {
console.log(data);
});
},
(在api/index.js文件中)
const myPost = axios.create({
baseURL: urls.baseUrl,
method: 'post',
headers: {
'token': sessionStorage.getItem("token")
},
})
const myGet = axios.create({
baseUR
从后台拿到token后存到headers中方法 AXios的方法
最新推荐文章于 2022-04-14 17:10:31 发布