• element-ui+vue上传图片和评论现成完整html页面


    其他更多具体完整项目源码可以私聊我,需要付一点点费用哟~

    效果展示

    主要部分的代码讲解

    上传图片

    首先是先通过el标签中的el-upload标签进行图片的上传,然后发送了一条/common/upload请求到服务端进行图片的上传。而on-success进行监听,上传成功后调用函数,将图片的url地址传到form表单中进行回显

    上传成功后调用的函数,将返回的数据传到ruleForm中的image

    对照片格式进行检验

    上传评论

    此处使用的还是el的标签el-input,通过v-model与form表单进行绑定,将数据保存在表单中

    当操作完成的时候点击保存按钮触发submitForm函数

    这个函数的操作是将ruleForm表单的数据保存到params中,然后将表单参数封装发送请求

    发送post请求 

    代码展示 

    html

    1. "en">
    2. "UTF-8">
    3. "X-UA-Compatible" content="IE=edge">
    4. "viewport" content="width=device-width, initial-scale=1.0">
    5. 评论
    6. "stylesheet" href="../../backend/plugins/element-ui/index.css"/>
    7. "stylesheet" href="../../backend/styles/common.css"/>
    8. "stylesheet" href="../../backend/styles/page.css"/>
    9. "addBrand-container" id="comment-app">
    10. "container">
    11. ref="ruleForm"
    12. :model="ruleForm"
    13. :rules="rules"
    14. :inline="true"
    15. label-width="180px"
    16. class="demo-ruleForm"
    17. >
    18. label="菜品图片:"
    19. prop="region"
    20. class="uploadImg"
    21. >
    22. class="avatar-uploader"
    23. action="/common/upload"
    24. :show-file-list="false"
    25. :on-success="handleAvatarSuccess"
    26. :on-change="onChange"
    27. ref="upload"
    28. >
    29. v-if="imageUrl"
    30. :src="imageUrl"
    31. class="avatar"
    32. >
    33. v-else
    34. class="el-icon-plus avatar-uploader-icon"
    35. >
  • "address">
  • label="菜品描述:"
  • prop="region"
  • >
  • v-model="ruleForm.description"
  • type="textarea"
  • :rows="3"
  • placeholder="菜品描述,最长200字"
  • maxlength="200"
  • />
  • "subBox address">
  • @click="goBack()">
  • 取消
  • type="primary"
  • @click="submitForm('ruleForm')"
  • >
  • 保存
  • css

    1. .dashboard-container {
    2. padding: 20px;
    3. }
    4. .dashboard-container .container {
    5. background: #fff;
    6. position: relative;
    7. z-index: 1;
    8. padding: 30px 28px;
    9. border-radius: 4px;
    10. }
    11. .dashboard-container .container .tableBar {
    12. display: flex;
    13. margin-bottom: 20px;
    14. justify-content: space-between;
    15. }
    16. .dashboard-container .container .tableBox {
    17. width: 100%;
    18. border: solid 2px #f3f4f7;
    19. border-radius: 2px;
    20. }
    21. .dashboard-container .container .tableBox .el-image img {
    22. width: 40px;
    23. border-radius: 5px;
    24. }
    25. .dashboard-container .container .pageList {
    26. text-align: center;
    27. margin-top: 30px;
    28. }
    29. .dashboard-container .container .tableLab .span-btn {
    30. cursor: pointer;
    31. display: inline-block;
    32. font-size: 14px;
    33. padding: 0 20px;
    34. color: #818693;
    35. border-right: solid 1px #d8dde3;
    36. }
    37. .dashboard-container .container .tableLab .el-button {
    38. margin-left: 10px;
    39. }
    40. .el-table-column--selection .cell {
    41. padding-left: 10px;
    42. }
    43. /* 添加 */
    44. .addBrand-container .avatar-uploader .el-upload {
    45. border: 1px dashed #d9d9d9;
    46. border-radius: 6px;
    47. cursor: pointer;
    48. position: relative;
    49. overflow: hidden;
    50. }
    51. .addBrand-container .avatar-uploader .el-upload:hover {
    52. border-color: #409eff;
    53. }
    54. .addBrand-container .avatar-uploader-icon {
    55. font-size: 28px;
    56. color: #8c939d;
    57. width: 200px;
    58. height: 160px;
    59. line-height: 160px;
    60. text-align: center;
    61. }
    62. .addBrand-container .avatar {
    63. width: 160px;
    64. height: 160px;
    65. display: block;
    66. }
    67. .addBrand-container .el-form--inline .el-form-item__content {
    68. width: 293px;
    69. }
    70. .addBrand-container .el-input {
    71. width: 293px;
    72. }
    73. .addBrand-container {
    74. margin: 30px;
    75. }
    76. .addBrand-container .container {
    77. position: relative;
    78. z-index: 1;
    79. background: #fff;
    80. padding: 30px;
    81. border-radius: 4px;
    82. min-height: 500px;
    83. }
    84. .addBrand-container .container .subBox {
    85. padding-top: 30px;
    86. text-align: center;
    87. border-top: solid 1px #f3f4f7;
    88. }
    89. .flavorBox {
    90. width: 777px;
    91. }
    92. .flavorBox .addBut {
    93. background: #ffc200;
    94. display: inline-block;
    95. padding: 0px 20px;
    96. border-radius: 3px;
    97. line-height: 40px;
    98. cursor: pointer;
    99. border-radius: 4px;
    100. color: #333333;
    101. font-weight: 500;
    102. }
    103. .flavorBox .flavor {
    104. border: solid 1px #dfe2e8;
    105. border-radius: 3px;
    106. padding: 15px;
    107. background: #fafafb;
    108. }
    109. .flavorBox .flavor .title {
    110. color: #606168;
    111. }
    112. .flavorBox .flavor .cont .items {
    113. display: flex;
    114. margin: 10px 0;
    115. }
    116. .flavorBox .flavor .cont .items .itTit {
    117. width: 150px;
    118. margin-right: 15px;
    119. }
    120. .flavorBox .flavor .cont .items .itTit input {
    121. width: 100%;
    122. line-height: 40px;
    123. border-radius: 3px;
    124. padding: 0 10px;
    125. }
    126. .flavorBox .flavor .cont .items .labItems {
    127. flex: 1;
    128. display: flex;
    129. flex-wrap: wrap;
    130. border-radius: 3px;
    131. min-height: 39px;
    132. border: solid 1px #d8dde3;
    133. background: #fff;
    134. padding: 0 5px;
    135. }
    136. .flavorBox .flavor .cont .items .labItems span {
    137. display: inline-block;
    138. color: #f19c59;
    139. margin: 5px;
    140. line-height: 26px;
    141. height: 26px;
    142. padding: 0 10px;
    143. background: #fdf4eb;
    144. border-radius: 3px;
    145. border: solid 1px #fae2cd;
    146. }
    147. .flavorBox .flavor .cont .items .labItems span i {
    148. cursor: pointer;
    149. font-style: normal;
    150. }
    151. .flavorBox .flavor .cont .items .labItems .inputBox {
    152. display: inline-block;
    153. width: 100%;
    154. height: 36px;
    155. line-height: 36px;
    156. overflow: hidden;
    157. }
    158. .flavorBox .flavor .cont .items .delFlavor {
    159. display: inline-block;
    160. padding: 0 10px;
    161. color: #f19c59;
    162. cursor: pointer;
    163. }
    164. .addBrand-container .address .el-form-item__content {
    165. width: 777px !important;
    166. }
    167. .el-button--text {
    168. font-weight: 400 !important;
    169. font-size: 13px !important;
    170. }
    171. .el-table td {
    172. font-size: 13px !important;
    173. }
    174. .el-table .cell,
    175. .el-table th div,
    176. .el-table--border td:first-child .cell,
    177. .el-table--border th:first-child .cell {
    178. padding-left: 12px;
    179. }

  • 相关阅读:
    【操作系统】第一章:概述
    IDEA—右边maven模块不见了
    生成对抗性网络简介
    云原生平台,让边缘应用玩出花!
    HashMap高频面试题,让你掌握青铜回答与王者级回答,你值得拥有
    【C语言】深度剖析动态内存管理
    node开发MongoDB
    P5906 【模板】回滚莫队&不删除莫队
    leetcode/两个链表的第一个重合节点
    Dubbo线程池
  • 原文地址:https://blog.csdn.net/m0_62314761/article/details/133122575