store.js
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {
user: "lzq920",
namespace: "lzq920/blog"
},
mutations: {},
actions: {}
});
home.vue
<template>
<div class="home">
<p>{{UserInfo}}</p>
<p>{{UserDocs}}</p>
<p>{{DocDetail}}</p>
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: "home",
components: {},
data() {
return {
UserInfo: {},
UserDocs: [],
DocDetail: {}
};
},
methods: {
getUserInfo() {
this.$axios
.get("/users/" + this.$store.state.user)
.then(res => {
this.UserInfo = res.data.data;
})
.catch(err => {
console.log(err);
});
},
getUserDocs() {
this.$axios
.get("/repos/" + this.$store.state.namespace + "/docs")
.then(res => {
this.UserDocs = res.data.data;
})
.catch(err => {
console.log(err);
});
},
getDocDetail() {
this.$axios
.get("/repos/" + this.$store.state.namespace + "/docs/die09g", {
params: {
raw: 1
}
})
.then(res => {
this.DocDetail = res.data;
})
.catch(err => {
console.log(err);
});
}
},
mounted() {
this.getUserInfo();
this.getUserDocs();
this.getDocDetail();
}
};
</script>