vue.js - 将砌体应用于 vue 网格项目的简单方法?
问题描述
有没有一种简单的方法可以将砌体应用于 Vue 中的网格项目?我一直在这里搜索教程和问题,但我无法成功地将 Masonry 应用到我的应用程序中。我正在寻找一种使用 Masonry 自动放置和调整图像大小的方法:
<template>
<div class="row" v-if="othersImages">
<div class="col" v-if="errors">
<div class="alert alert-danger"><p>{{ errors }}</p></div>
</div>
<div id="others-images" class="grid">
<div class="grid-item" v-for="image in othersImages" :key="image.id">
<h5>{{ image.name }}</h5>
<picture v-bind="'image' + image.id">
<img v-bind:src="image.image.path" v-bind:alt="image.description"/>
</picture>
</div>
<div class="clearfix"></div>
</div>
</div>
</template>
<script>
export default {
name: 'othersImages',
created() {
this.fetchImages();
},
data() {
return {
apiRequest: new this.$request(),
othersImages: [],
errors: '',
};
},
methods: {
fetchImages() {
const endpoint = 'images';
this.apiRequest.get(endpoint)
.then((response) => {
this.othersImages = response;
this.errors = '';
})
.catch((errors) => {
this.errors = errors;
});
},
},
};
</script>
解决方案
<template>
<div data-masonry='{"percentPosition": true }' class="row">
<div class="full col-lg-4 half"></div>
<div class="half col-lg-4"></div>
<div class="full col-lg-4"></div>
<div class="full col-lg-4"></div>
<div class="half col-lg-4"></div>
<div class="full col-lg-4"></div>
<div class="full col-lg-4"></div>
<div class="half col-lg-4"></div>
<div class="full col-lg-4"></div>
<div class="full col-lg-4"></div>
</div>
</template>
<script>
export default {}
</script>
<style>
.row {
width: 80vw;
height: 600px;
background-color: green;
margin: auto;
}
.full {
height: 150px;
background-color: grey;
border: 1px solid black;
}
.half {
height: 75px;
background-color: grey;
border: 1px solid black;
}
</style>
您应该将引导程序和砌体 CDN 添加到您的项目中,然后只需添加
数据砌体='{"percentPosition": true }'
排到你的行,砌体会自动工作。查看此链接了解更多信息。
推荐阅读
- reactjs - 如何使用 Ionic React 检查网络连接?
- python - 使用Python和imgkit,基于浏览器渲染的html,输出不如预期
- mysql - (MYSQL) 为什么我不能同时使用 2 个函数 COUNT 和 MAX。最大(计数(*))
- cognos-10 - 需要帮助才能在没有 html 分页的情况下运行报告
- spring - 在@Configuration 中配置 token-info-uri 和 jwk.key-set.uri
- apache-directory - 在 macOS 中全新安装 Apache Directory Studio 无法启动新的 LDAP 服务器
- css - ngbModal 内容不会根据引导 CSS 调整大小
- javascript - 使用jQuery根据输入文本值禁用下拉菜单
- nuxt.js - 获取数组每一项的数据
- html - 在将 html 字符串转换为 pdf 期间不应用 PDFTron flex 样式