用Element -ui的Description组件动态展示组件内的信息

                今天遇到的问题是我想要创建一个展示个人信息的描述列表,然后我就找到了Element里面的Description描述列表组件

                但在使用的时候就发现了一个问题,就是这个列表中对应属性的内容时通过创建列表时输入好的,我就没有办法通过Vue中的V-model来动态变化这里面的数据,更没有办法连接数据库,来获取数据库里面的内容并让这个列表内容随之改变。

 

                于是,我尝试了各种各样的方法,先是找了我之前成功能够动态获取并且展示数据的方法,

 例如上图是个表单模型,我在表单里面使用了<el-input></el-input>,达到了通过v-model的数据模型来动态修改,展示数据的效果。但当我用到了描述列表中,又发现了问题

 

                 数据确确实实是动态展示出来了,但是,有个文本输入框,不符合我设计的预期。于是这个方法就pass掉。

                在我随便尝试的时候,我突然想到,之前好像有个用法就是两个大括号里面来传入数据模型,这样可以直接获取数据模型的值,于是我抱着试一试的心情用了这个方法。

结果成功了。

                但究竟为什么两个大括号里面包裹了数据模型就能达到效果呢。

                我上网查了相关资料,发现,这好像就是Vue.js中的规定。

                以后记得这么用就可以 

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
1. 安装element-ui: `npm install element-ui --save` 2. 引入element-ui和样式文件 ```javascript import Vue from 'vue' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' Vue.use(ElementUI) ``` 3. 创建Carousel组件 ```vue <template> <el-carousel :interval="interval"> <el-carousel-item v-for="(item, index) in list" :key="index"> <div class="card"> <div class="card-img"> <img :src="item.imgUrl" alt=""> </div> <div class="card-info"> <h3>{{ item.title }}</h3> <p>{{ item.desc }}</p> <a :href="item.link" target="_blank">了解更多</a> </div> </div> </el-carousel-item> </el-carousel> </template> <script> export default { name: 'MyCarousel', props: { list: { type: Array, default: () => [] }, interval: { type: Number, default: 3000 } } } </script> <style scoped> .card { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 200px; width: 300px; background-color: #fff; border-radius: 4px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .card-img { height: 120px; width: 100%; overflow: hidden; border-radius: 4px 4px 0 0; } .card-img img { height: 100%; width: 100%; object-fit: cover; } .card-info { padding: 16px; text-align: center; } .card-info h3 { font-size: 18px; margin-bottom: 10px; } .card-info p { font-size: 14px; margin-bottom: 10px; color: #999; } .card-info a { display: inline-block; font-size: 14px; color: #409eff; } </style> ``` 4. 在父组件中使用Carousel组件 ```vue <template> <my-carousel :list="list" /> </template> <script> import MyCarousel from './MyCarousel.vue' export default { components: { MyCarousel }, data() { return { list: [ { imgUrl: 'https://picsum.photos/300/200/?image=10', title: 'Card Title 1', desc: 'Card Description 1', link: 'https://www.example.com' }, { imgUrl: 'https://picsum.photos/300/200/?image=20', title: 'Card Title 2', desc: 'Card Description 2', link: 'https://www.example.com' }, { imgUrl: 'https://picsum.photos/300/200/?image=30', title: 'Card Title 3', desc: 'Card Description 3', link: 'https://www.example.com' }, { imgUrl: 'https://picsum.photos/300/200/?image=40', title: 'Card Title 4', desc: 'Card Description 4', link: 'https://www.example.com' } ] } } } </script> ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值