commentTitle.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="comment">
  3. <p class="comment-title">
  4. <span>评论</span>
  5. <span>({{dataLength}})</span>
  6. </p>
  7. <div class="commentMyinfo">
  8. <img :src="myuser.user_img" alt="" v-if="myuser">
  9. <img src="@/assets/default_img.jpg" alt="" v-else>
  10. <input v-model="comcontent" ref="Postipt" type="text" placeholder="说点什么吧">
  11. <button @click="cmmentPublish">发表</button>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. props:['dataLength'],
  18. data() {
  19. return {
  20. myuser:null,
  21. comcontent:'',
  22. }
  23. },
  24. methods: {
  25. async myUserinfo() {
  26. const res = await this.$http.get("/user/" + localStorage.getItem("id"));
  27. this.myuser = res.data[0];
  28. },
  29. cmmentPublish() {
  30. if(!this.myuser && !localStorage.getItem('token')&& !localStorage.getItem('id')){
  31. this.$msg.fail('请先登录')
  32. return
  33. }
  34. this.$emit('Postcomment',this.comcontent)
  35. this.comcontent = ''
  36. },
  37. focusIpt(){
  38. this.$refs.Postipt.focus()
  39. }
  40. },
  41. created() {
  42. if(localStorage.getItem('token')){
  43. this.myUserinfo();
  44. }
  45. },
  46. };
  47. </script>
  48. <style lang="less">
  49. .comment{
  50. padding: 8.333vw 2.778vw 0 2.7778vw;
  51. .comment-title{
  52. span:nth-child(2) {
  53. color: #aaa;
  54. margin-left: 2.778vw;
  55. }
  56. }
  57. .commentMyinfo{
  58. padding: 2.778vw 0;
  59. display: flex;
  60. img{
  61. height: 7.944vw;
  62. width: 7.944vw;
  63. border-radius: 50%;
  64. }
  65. input{
  66. outline: none;
  67. border: 0;
  68. background-color: #f4f4f4;
  69. border-radius: 3.611vw;
  70. font-size: 3.333vw;
  71. padding: 0 5.556vw 0 4.167vw;
  72. margin-left: 2.778vw;
  73. }
  74. button{
  75. outline: none;
  76. border: 0;
  77. border-radius: 3.333vw;
  78. background: #fb7299;
  79. color: white;
  80. font-size: 3.333vw;
  81. padding: 0 4.167vw;
  82. }
  83. }
  84. }
  85. </style>