Article.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <el-row>
  3. <el-col :span="14" :offset="5">
  4. <el-container>
  5. <el-header style="font-size: 35px">
  6. {{ article.article_title }}
  7. </el-header>
  8. <el-main style="text-align: left">
  9. <el-container>
  10. <el-header>
  11. <div id="avatar">
  12. <el-avatar :size="40" :src="circleUrl"></el-avatar>
  13. <div id="author_name">{{ authorName }}</div>
  14. </div>
  15. </el-header>
  16. <el-main v-html="content"></el-main>
  17. </el-container>
  18. </el-main>
  19. <el-footer></el-footer>
  20. </el-container>
  21. </el-col>
  22. </el-row>
  23. </template>
  24. <script>
  25. export default {
  26. components: [],
  27. data() {
  28. return {
  29. article: {},
  30. articleID: 0,
  31. content: "",
  32. authorName: "",
  33. circleUrl:
  34. "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
  35. };
  36. },
  37. mounted() {
  38. this.articleID = this.$route.params.id;
  39. this.getArticle(this.articleID);
  40. },
  41. methods: {
  42. getArticle(id) {
  43. this.$axios.get(`/articles/${id}`).then((response) => {
  44. const result = response.data[0];
  45. this.article = result;
  46. this.content = result.content;
  47. this.getAuthor(result.author_id);
  48. });
  49. },
  50. getAuthor(id) {
  51. this.$axios.get(`/users/info/${id}`).then((response) => {
  52. console.log(response);
  53. this.authorName = response.data[0].user_name;
  54. });
  55. },
  56. },
  57. };
  58. </script>
  59. <style>
  60. #avatar {
  61. text-align: left;
  62. margin-top: 10px;
  63. margin-bottom: 20px;
  64. margin-left: 20px;
  65. position: relative;
  66. }
  67. #author_name {
  68. display: inline;
  69. font-size: 15px;
  70. position: absolute;
  71. top: 21%;
  72. margin-left: 10px;
  73. }
  74. </style>