1. 在template 中使用assets中的图片

<template>
    <div class="wrapper">
        <div class="item" v-for="item, index in list" :key="index" draggable="true"  @dragstart="dragStart(item,index)" @dragover.prevent="dragOver(index)" @drop="dragEnd()"
             >
            <!-- {{ item.name }} -->
            <img  style="width:100%;height:100%;" :src="item.imgUrl" alt="">
        </div>
    </div>
</template>



 list: [
                {
                    name: "1",
                    imgUrl:require(`@/assets/images/1.jpeg`)
                }, {
                    name: "2",
                    imgUrl: require(`@/assets/images/2.jpeg`)
                }, {
                    name: "3",
                    imgUrl: require(`@/assets/images/3.jpeg`)
                }, {
                    name: "4",
                    imgUrl: require(`@/assets/images/5.jpeg`)
                }, {
                    name: "5",
                    imgUrl: require(`@/assets/images/6.jpeg`)
                }, {
                    name: "6", 
                    imgUrl: require(`@/assets/images/7.jpeg`)
                }, {
                    name: "7",
                    imgUrl: require(`@/assets/images/8.jpg`)
                }, {
                    name: "8", 
                    imgUrl: require(`@/assets/images/9.jpg`)
                }
            ],
  1. 在template 中使用public中的图片(相对路径)
<template>
    <div class="wrapper">
        <div class="item" v-for="item, index in list2" :key="index" draggable="true"  @dragstart="dragStart(item,index)" @dragover.prevent="dragOver(index)" @drop="dragEnd()"
             >
            <!-- {{ item.name }} -->
            <img  style="width:100%;height:100%;" :src="item.imgUrl" alt="">
        </div>
    </div>
</template>


   list2: [
                {
                    name: "1",
                    imgUrl:"../../static/images/1.jpeg" 
                }, {
                    name: "2",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "3",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "4",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "5",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "6",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "7",
                    imgUrl: "../../static/images/1.jpeg"
                }, {
                    name: "8",
                    imgUrl: "../../static/images/1.jpeg"
                }
            ],

3.在css中使用assets中的图片(相对路径)

.wrapper {
    height: 100%;

    .item {
        background: url('../assets/images/1.jpeg') no-repeat;
        background-size: cover;
        height: 250px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        /* width: 25%; */
        /* float: left; */
        /* padding: 24px 16px 0; */
        /* margin-bottom: 6px; */
        /* height: 250px; */
        width: 25%;
        float: left;
        padding: 24px 16px 0;
        margin-bottom: 6px;
        box-sizing: border-box;
    }
}

4.在css中使用public中的图片(相对路径)

.wrapper {
    height: 100%;

    .item {
        background: url("../../public/static/images/1.jpeg") no-repeat;
        background-size: cover;
        height: 250px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
        /* width: 25%; */
        /* float: left; */
        /* padding: 24px 16px 0; */
        /* margin-bottom: 6px; */
        /* height: 250px; */
        width: 25%;
        float: left;
        padding: 24px 16px 0;
        margin-bottom: 6px;
        box-sizing: border-box;
    }
}
GitHub 加速计划 / vu / vue
109
18
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:3 个月前 )
9e887079 [skip ci] 1 年前
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐