Browse Source

image为空时不渲染comment-item-image

narro 6 years ago
parent
commit
976305af5a

+ 6
- 2
lib/components/ContentItem/index.js View File

@@ -143,6 +143,8 @@ var CommentItem = function (_Component) {
143 143
         newContent = newContent.join("");
144 144
       }
145 145
 
146
+      var imageList = images.split(",");
147
+
146 148
       return _react2.default.createElement(
147 149
         "div",
148 150
         { className: "comment-item-box" },
@@ -181,10 +183,12 @@ var CommentItem = function (_Component) {
181 183
               __html: (0, _helper.renderContent)(this.renderTextWithReply(newContent, content))
182 184
             }
183 185
           }),
184
-          _react2.default.createElement(
186
+
187
+          // image为空时不渲染comment-item-image
188
+          imageList.length > 0 && imageList[0] !== '' && _react2.default.createElement(
185 189
             "div",
186 190
             { className: "comment-item-image" },
187
-            images.split(",").map(function (item, index) {
191
+            imageList.map(function (item, index) {
188 192
               return _react2.default.createElement("img", {
189 193
                 key: index,
190 194
                 src: item,

+ 1
- 1
lib/components/ContentItem/index.js.map
File diff suppressed because it is too large
View File


+ 1
- 1
lib/components/Editor/index.js.map
File diff suppressed because it is too large
View File


+ 18
- 12
src/components/ContentItem/index.js View File

@@ -70,6 +70,8 @@ class CommentItem extends Component {
70 70
       newContent = newContent.join("");
71 71
     }
72 72
 
73
+    const imageList = images.split(",");
74
+
73 75
     return (
74 76
       <div className="comment-item-box">
75 77
         <div className="comment-item-left">
@@ -100,18 +102,22 @@ class CommentItem extends Component {
100 102
               )
101 103
             }}
102 104
           />
103
-          <div className="comment-item-image">
104
-            {images.split(",").map((item, index) => {
105
-              return (
106
-                <img
107
-                  key={index}
108
-                  src={item}
109
-                  alt={item}
110
-                  style={{ maxWidth: "100%" }}
111
-                />
112
-              );
113
-            })}
114
-          </div>
105
+          {// image为空时不渲染comment-item-image
106
+          imageList.length > 0 &&
107
+            imageList[0] !== "" && (
108
+              <div className="comment-item-image">
109
+                {imageList.map((item, index) => {
110
+                  return (
111
+                    <img
112
+                      key={index}
113
+                      src={item}
114
+                      alt={item}
115
+                      style={{ maxWidth: "100%" }}
116
+                    />
117
+                  );
118
+                })}
119
+              </div>
120
+            )}
115 121
           <div className="comment-item-bottom">
116 122
             {content.reply_count ? (
117 123
               <div>