首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >引导-Vue组件自定义卡

引导-Vue组件自定义卡
EN

Stack Overflow用户
提问于 2020-09-18 15:40:12
回答 1查看 1.2K关注 0票数 0

我开始学习VueJS 2编程。我需要在我的网站上添加卡片。我创建了自己的组件' Cards.vue ',我已经包含了由自举-Vue Cards.vue生成的卡片组件应该在Home.vue中使用。我必须修改Home.vue中的几个“img”。

Cards.vue代码:

代码语言:javascript
复制
    <template>
    <div>
      <b-card
        title="Card Title"
        img-src="../../assets/images/fondLBM.png"
        img-alt="One's image alt"
        img-top
        tag="article"
        style="max-width: 20rem;"
        class="mb-2"
      >
        <b-card-text>
          <slot name="text"> 
"Some quick example text to build on the card title and make up the bulk of the card's content."</slot>
        </b-card-text>

        <b-button href="#" variant="primary">
            <slot name="button-txt"> Go somewhere </slot>
        </b-button>
      </b-card>
    </div>
    </template>

    <script>
    export default{
        name : 'CardS'
    }
    </script>

我在Home.vue中的代码:

代码语言:javascript
复制
    <section class="bg-light py-5">
      <h2>Section</h2>
      <b-container>
        <b-row>
          <b-col>
            <bscard>
              
              <template v-slot:text>
                <p>One's product</p>
              </template>
              <template v-slot:button-txt>
                <span>Got it !</span>
              </template>
            </bscard>
          </b-col>
          <b-col>
            <bscard imgsrc="imgsrc[1]">
              <template v-slot:text>
                <p>One's product</p>
              </template>
              <template v-slot:button-txt>
                <span>Got it !</span>
              </template>
            </bscard>
          </b-col>
          <b-col>
            <bscard v-bind:imgsrc="imgsrc[2]">
              <template v-slot:text>
                <p>One's product</p>
              </template>
              <template v-slot:button-txt>
                <span>Got it !</span>
              </template>
            </bscard>
          </b-col>
        </b-row>
      </b-container>
    </section>
<script>
// @ is an alias to /src
import CardS from "@/components/Contents/Cards.vue";

export default {
  name: "Home",
  components: {
    bscard: CardS
  },
  data(){
    return {
      imgsrc : [
      'https://picsum.photos/600/300/?image=25', 
      'https://picsum.photos/600/300/?image=25', 
      'https://picsum.photos/600/300/?image=25']
    }
  }
}
</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-18 15:49:32

如果您想在您的卡中添加一个图像,您应该添加一个道具到您的组件。

https://v2.vuejs.org/v2/guide/components-props.html

代码语言:javascript
复制
<script>
export default{
    name : 'CardS',
    props:["imagePath"]

}
</script>

在你的模板里

代码语言:javascript
复制
<template>
...
<img
:scr:"imagePath"
</template>

在你的主页上

<bscard :src="imgsrc[1]">

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63958802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档