store.js

  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. Vue.use(Vuex);
  4. export default new Vuex.Store({
  5. state: {
  6. user: "lzq920",
  7. namespace: "lzq920/blog"
  8. },
  9. mutations: {},
  10. actions: {}
  11. });

home.vue

  1. <template>
  2. <div class="home">
  3. <p>{{UserInfo}}</p>
  4. <p>{{UserDocs}}</p>
  5. <p>{{DocDetail}}</p>
  6. </div>
  7. </template>
  8. <script>
  9. // @ is an alias to /src
  10. export default {
  11. name: "home",
  12. components: {},
  13. data() {
  14. return {
  15. UserInfo: {},
  16. UserDocs: [],
  17. DocDetail: {}
  18. };
  19. },
  20. methods: {
  21. getUserInfo() {
  22. this.$axios
  23. .get("/users/" + this.$store.state.user)
  24. .then(res => {
  25. this.UserInfo = res.data.data;
  26. })
  27. .catch(err => {
  28. console.log(err);
  29. });
  30. },
  31. getUserDocs() {
  32. this.$axios
  33. .get("/repos/" + this.$store.state.namespace + "/docs")
  34. .then(res => {
  35. this.UserDocs = res.data.data;
  36. })
  37. .catch(err => {
  38. console.log(err);
  39. });
  40. },
  41. getDocDetail() {
  42. this.$axios
  43. .get("/repos/" + this.$store.state.namespace + "/docs/die09g", {
  44. params: {
  45. raw: 1
  46. }
  47. })
  48. .then(res => {
  49. this.DocDetail = res.data;
  50. })
  51. .catch(err => {
  52. console.log(err);
  53. });
  54. }
  55. },
  56. mounted() {
  57. this.getUserInfo();
  58. this.getUserDocs();
  59. this.getDocDetail();
  60. }
  61. };
  62. </script>