vue中本地靜態(tài)圖片的路徑應該怎么寫
更新時間:2023年10月17日 08:51:52 作者:開心大表哥
這篇文章主要介紹了vue中本地靜態(tài)圖片的路徑應該怎么寫,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue中本地靜態(tài)圖片的路徑應該怎么寫

需求
如何components里面的index.vue怎樣能把assets里面的圖片拿出來。
1.在img標簽里面直接寫上路徑:
<img src="../assets/a1.png" class="" width="100%"/>
2.利用數(shù)組保存再循環(huán)輸出:
<el-carousel-item v-for="item in carouselData" :key="item.id">
<img :src="item.url" class="carouselImg"/>
<span class="carouselSpan">{{ item.title }}</span>
</el-carousel-item>
data: () => ({
carouselData:[
{url:require('../assets/a1.png'),title:'你看我叼嗎1',id:1},
{url:require('../assets/a3.png'),title:'你看我叼嗎2',id:2},
{url:require('../assets/a4.png'),title:'你看我叼嗎3',id:3}
]
}),
效果如下:

index.vue里面的完整代碼是這個:
<template>
<div>
<div class=" block">
<el-carousel class="carouselBlock">
<el-carousel-item v-for="item in carouselData" :key="item.id">
<img :src="item.url" class="carouselImg"/>
<span class="carouselSpan">{{ item.title }}</span>
</el-carousel-item>
</el-carousel>
</div>
<footer1></footer1>
<img src="../assets/a1.png" class="" width="100%"/>
</div>
</template>
<script>
import footer1 from '../components/public/footer'
export default {
data: () => ({
carouselData:[
{url:require('../assets/a1.png'),title:'你看我叼嗎1',id:1},
{url:require('../assets/a3.png'),title:'你看我叼嗎2',id:2},
{url:require('../assets/a4.png'),title:'你看我叼嗎3',id:3}
]
}),
components:{
footer1
},
}
</script>
<style lang="scss">
@import '../style/mixin';
.carouselBlock{
width: 100%;
height: REM(300);
position:relative;
.carouselImg{
height: REM(300);
width:100%;
}
.carouselSpan{
position: absolute;
bottom: REM(20);
left: REM(20);
font-size: REM(24);
font-weight: bold;
}
}
.el-carousel__container{
width: 100%;
height: REM(300);
}
.el-carousel__item h3 {
color: #475669;
font-size: 14px;
opacity: 0.75;
margin: 0;
}
.el-carousel__item:nth-child(2n) {
background-color: #99a9bf;
}
.el-carousel__item:nth-child(2n+1) {
background-color: #d3dce6;
}
</style>
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue2+elementui上傳照片方式(el-upload超簡單)
這篇文章主要介紹了vue2+elementui上傳照片方式(el-upload超簡單),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
vue?proxytable代理根路徑的同時增加其他代理方式
這篇文章主要介紹了vue?proxytable代理根路徑的同時增加其他代理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
Vue.js實現(xiàn)簡單ToDoList 前期準備(一)
這篇文章主要介紹了Vue.js實現(xiàn)簡單ToDoList的前期準備,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12
vue使用ArcGis?API?for?js創(chuàng)建地圖實現(xiàn)示例
這篇文章主要為大家介紹了vue使用ArcGis?API?for?js創(chuàng)建地圖實現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08

