fuxingloh / vue-masonry-wall

A pure vue responsive masonry layout without direct dom manipulation and ssr support.
https://nuxt-app.fuxing.dev/vue-masonry-wall
MIT License
211 stars 31 forks source link

Width adaptive? #6

Closed StringKe closed 4 years ago

StringKe commented 4 years ago

Try to read the width of the parent element after the page loads? I am not sure about my width but I know that I need two columns to display the content

StringKe commented 4 years ago

When I replace items => detail.data, I get the following error, TypeError: Cannot read property 'preview' of undefined.

          <vue-masonry-wall
            :items="detail.data"
            :options="options"
            v-if="childrenLoad"
          >
            <template v-slot:default="{ item }">
              <div class="item bg-width rounded overflow-hidden">
                <img :src="assetsUrl(item.preview)" alt="bg" />
              </div>
            </template>
          </vue-masonry-wall>
StringKe commented 4 years ago

When I replace items => detail.data, I get the following error, TypeError: Cannot read property 'preview' of undefined.

          <vue-masonry-wall
            :items="detail.data"
            :options="options"
            v-if="childrenLoad"
          >
            <template v-slot:default="{ item }">
              <div class="item bg-width rounded overflow-hidden">
                <img :src="assetsUrl(item.preview)" alt="bg" />
              </div>
            </template>
          </vue-masonry-wall>

I use v-if to reload without this problem

StringKe commented 4 years ago

When options.width = 0 enable fixed number of columns?

https://github.com/fuxingloh/vue-masonry-wall/blob/fe983f6829c7bb54555e28e3d6c535a717687991/src/vue-masonry-wall.vue#L183

const length = Math.round(this.$refs.wall.scrollWidth / this._options.width)

change

const length = this._options.width != 0 ? Math.round(this.$refs.wall.scrollWidth / this._options.width) : this._options.cloumn;