Write a picture description here
Requirements: How to take out the pictures in the components?
1. Write the path directly in the img tag:
<img src="../assets/" class="" width="100%"/>
2. Use array to save the recycled output:
<el-carousel-item v-for="item in carouselData" :key=""> <img :src="" class="carouselImg"/> <span class="carouselSpan">{{ }}</span> </el-carousel-item> data: () => ({ carouselData:[ {url:require('../assets/'),title:'Do you think I'm 1',id:1}, {url:require('../assets/'),title:'Do you think I'm 2',id:2}, {url:require('../assets/'),title:'Do you think I'm 3',id:3} ] }),
The effects are as follows:
The complete code inside is this:
<template> <div> <div class=" block"> <el-carousel class="carouselBlock"> <el-carousel-item v-for="item in carouselData" :key=""> <img :src="" class="carouselImg"/> <span class="carouselSpan">{{ }}</span> </el-carousel-item> </el-carousel> </div> <footer1></footer1> <img src="../assets/" class="" width="100%"/> </div> </template> <script> import footer1 from '../components/public/footer' export default { data: () => ({ carouselData:[ {url:require('../assets/'),title:'Do you think I'm 1',id:1}, {url:require('../assets/'),title:'Do you think I'm 2',id:2}, {url:require('../assets/'),title:'Do you think I'm 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>
PS: Let's look at the image reference path below
When we reference images in our project, there are several situations regarding the image path:
Use one
We define the image path in data
imgUrl:'../assets/'
Then, inside the template template
<<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">img src=" {{imgUrl}}">
This is the wrong way to write it. We should use v-bind to bind the srcs attribute of the image
:src="imgUrl">
or
<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">img src="../assets/">
This method is to refer to the normal HTML syntax and place it in a template and can be packaged by webpack.
Use two
When we need to write the image path in the js code, if we write it in data
imgUrl:'../assets/'
At this time, webpack will only process it as a string and cannot find the image address. At this time, we can use import to introduce the image path:
:src="avatar" /> import avatar from '@/assets/'
Definition in data
avatar: avatar
Situation Three
We can also place the picture in the outer static folder and then define it in data:
imgUrl : '../../static/' :src="imgUrl" />
The above is how we reference the image path in it.