64.vue默认插槽

本文介绍了Vue.js中组件的使用,以Category.vue和App.vue为例,展示了如何创建一个带有插槽功能的Category组件,并在App.vue中进行使用。Category组件接收`listData`和`title`作为属性,通过插槽插入内容,如图片、视频等。App.vue中定义了不同类型的分类,如美食、游戏和电影,并分别提供了相应的数据。通过这种方式,实现了一个简单的分类展示功能。
摘要由CSDN通过智能技术生成

Category.vue

<template>
  <div class="category">
      <h3>{{title}}分类</h3>
      <slot>
          <ul>
              <li v-for="item in listData" :key="item">{{item}}</li>
          </ul>
      </slot>
      <!-- slot插槽将app里的图片指定到这个位置,挖个坑等图片来跳 -->
  </div>
</template>

<script>
export default {
    name:"TheCategory",
    props:['listData','title']
}
</script>

<style>
    .category{
        background-color: skyblue;
        width: 200px;
        height: 300px;
    }
    h3{
        text-align: center;
        background-color: orange;
    }
    li{
        text-align: left;
    }
</style>

App.vue

<template>
  <div id="app">
    <category title="美食">
      <img src="./assets/logo.png" alt="">
    </category>
    <category title="游戏" :listData="games"></category>
    <category title="电影">
      <video src="./assets/big_buck_bunny.mp4" controls autoplay></video>
    </category>
  </div>
</template>

<script>
import Category from './components/Category.vue';
export default {
  name: 'App',
  components:{Category},
  data() {
    return {
      foods: ['火锅','烧烤','小龙虾','牛排'],
      games:['英雄联盟','QQ飞车','穿越火线','地下城与勇士'],
      films:['《反贪风暴5》','《唐人街探案》','《西虹市首富》','《大人物》']
    };
  },
}
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  margin-top: 60px;
  display: flex;
  justify-content: space-around;
}
video{
  width: 100%;
}
</style>

main.js

import Vue from 'vue'
import App from './App.vue'
// npm i vue-resource引入插件
import vueResource from 'vue-resource';
//使用插件
Vue.use(vueResource);
new Vue({
  render: h => h(App),
}).$mount('#app');


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

修罗_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值