vue3<script setup>瀑布流写法

本文介绍了一个使用Vue.js编写的HTML模板,展示带有图片、标题和内容的列表,适合用于内容社区或博客展示。
摘要由CSDN通过智能技术生成

不想写步骤了,cv走用就行了

<template>
  <div>
    <div class="content">
      <div class="list" v-for="(item, index) in itemList" :key="index">
        <img class="image" :src="item.imageSrc" alt="item image">
        <div class="title">{{ item.title }}</div>
        <div class="con">{{ item.content }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
const itemList = [
  {
    imageSrc: 'https://pic.imgdb.cn/item/65084fd3204c2e34d3a96817.jpg',
    title: '我是标题1',
    content: '我是内容1',
  },
  {
    imageSrc: 'https://pic.imgdb.cn/item/650850d7204c2e34d3a984ca.jpg',
    title: '我是标题2',
    content: '我是内容2',
  },
  {
    imageSrc: 'https://pic.imgdb.cn/item/64eee7e1661c6c8e54a86a07.jpg',
    title: '我是标题3',
    content: '我是内容3',
  },
  {
    imageSrc: 'https://pic.imgdb.cn/item/65085109204c2e34d3a9933c.jpg',
    title: '我是标题4',
    content: '我是内容4',
  },
  {
    imageSrc: 'https://pic.imgdb.cn/item/65084fd3204c2e34d3a96817.jpg',
    title: '我是标题5',
    content: '我是内容5',
  },
];
</script>

<style scoped>
.content {
  padding: 30rpx;
  box-sizing: border-box;
  column-count: 2;
}
.image {
  width: 100%;
  border-radius: 6rpx;
}
.title {
  margin-left: 15rpx;
  margin-right: 15rpx;
  font-size: 30rpx;
}
.con {
  margin: 15rpx;
  margin-top: 20rpx;
  display: flex;
  font-size: 26rpx;
  align-items: center;
  justify-content: space-between;
}
.list {
  break-inside: avoid;
  width: 330rpx;
  border: 1px solid #f4f4f4;
}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue 3中,`<script setup>`是一个新的语法糖,它可以更简洁地编写组件的逻辑部分。通过`<script setup>`,你可以在组件中使用Composition API,而无需显式地导入和使用`import { ... } from 'vue'`。 下面是使用`<script setup>`的基本用法: 1. 首先,在Vue 3的单文件组件中,将`<script>`标签替换为`<script setup>`。 2. 在`<script setup>`中,你可以直接使用Composition API提供的函数和响应式变量,无需显式导入。例如,你可以直接使用`ref`、`reactive`、`computed`等函数。 3. 在`<script setup>`中,你可以使用`defineProps`和`defineEmits`来定义组件的属性和事件。这样可以更方便地声明和使用组件的属性和事件。 4. 在`<script setup>`中,你可以使用`onXXX`的方式来定义组件的生命周期钩子函数。例如,你可以使用`onMounted`、`onUpdated`等函数。 下面是一个简单的示例,展示了如何使用`<script setup>`: ```vue <template> <div> <p>{{ count }}</p> <button @click="increment">Increment</button> </div> </template> <script setup> import { ref } from 'vue' const count = ref(0) function increment() { count.value++ } </script> ``` 在上面的示例中,我们使用了`<script setup>`来定义了一个计数器组件。通过`ref`函数创建了一个响应式变量`count`,并定义了一个`increment`函数来增加计数器的值。在模板中,我们直接使用了`count`变量和`increment`函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

锅盖哒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值