Sfoglia il codice sorgente

Merge branch 'dev/v1.2.16_wmh' of jianyu/jy-docs into feature/v1.2.16

wenmenghao 10 mesi fa
parent
commit
49dd856088
1 ha cambiato i file con 12 aggiunte e 6 eliminazioni
  1. 12 6
      jydocs-pc/src/components/SelectedRecommend.vue

+ 12 - 6
jydocs-pc/src/components/SelectedRecommend.vue

@@ -45,12 +45,18 @@ export default {
       default: () => []
     }
   },
+  watch: {
+    options (val) {
+      if (val.length > 0) {
+        this.$nextTick(() => {
+          this.setItemwidth()
+        })
+      }
+    }
+  },
   data () {
     return {}
   },
-  mounted () {
-    this.setItemwidth()
-  },
   methods: {
     handleError (img) {
       img.target.src = require('../assets/images/error.png')
@@ -71,10 +77,10 @@ export default {
     setItemwidth () { // 适配嵌入工作台内
       const bodyWidth = document.body.clientWidth
       if (window.goTemplateData && window.goTemplateData.inIframe && bodyWidth > 1248) {
-        const element = document.getElementsByClassName('card-item')[0]
+        const element = document.querySelectorAll('.card-item')[0]
         const itemwidth = element.offsetWidth + 104 // 104是margin
-        const num = Math.floor(bodyWidth / itemwidth)
-        const newwidth = (Math.floor((bodyWidth - (itemwidth * num)) / num)) + itemwidth
+        const num = Math.floor((bodyWidth - 48) / itemwidth)
+        const newwidth = ((Math.floor((bodyWidth - (itemwidth * num) - 48) / num)) + itemwidth) - 104
         var elements = document.querySelectorAll('.card-item')
         elements.forEach(function (ele) {
           ele.style.width = newwidth + 'px' // 设置新的宽度