0
点赞
收藏
分享

微信扫一扫

64.vue默认插槽

夏天的枫_ 2022-02-24 阅读 70

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');


举报

相关推荐

0 条评论