<img :src="image"/>
When we dynamically load pictures, an error will appear as shown in the following figure
1. The first possibility is that you write a relative path, and you need to write an absolute path
image:'../assets/image/top10-1.png'
You need to change to the specific path
image:'/src/assets/images/top10-1.png'
2. The second solution is to use require ()
<img :src="require(images)"/>
3. The third solution is to put the pictures under the public directory, but although this solves the problem, the files in this directory will not be packaged when using webpack
4. If you use ts, you cannot use require (). You can use import to import your picture path as a module
<template>
<img :src="images"/>
</template>
<script>
import image from '../assets/image/top10-1.png'
export default{
data(){
return {
images:image
}
}
}
</script>
Read More:
- CSS to achieve dynamic display of picture text by mouse touch
- Vue picture display 403 error [How to Solve]
- [Solved] Vue binding dynamic inline style Error: transform:rotate()
- [Solved] Vue Import swiper.css Error: Module not found…
- Vue Project Error: Expected indentation of 2 spaces but found 4,Newline required at end of file but not found
- [Solved] Vue E-Charts Error: These dependencies were not found:
- [Solved] Vue Project Error: This relative module was not found
- Vue Start Error: This relative module was not found:
- Vue Startup Error: 98% after emitting CopyPlugin This dependency was not found:
- [Solved] Vue item packaging error: Failed to load resource: the server responded with a status of 404 (Not Found)
- [Solved] Vue Error: Uncaught TypeError: Vue.createApp is not a function
- [Solved] Vue Route Error: Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_42__.defineComponent) is not a function
- [Solved] Vue3.0 Error: The component has been registered but not used vue/no-unused-components, Close eslint
- [Solved] Vue Less error: Webpack project report expected indentation of 0 spaces but found 2
- Vue-router import Dynamic Module Error [How to Solve]
- [Solved] Vue Project startup error: no eslint configuration found
- [Solved] Vue uses webpack to package error: Createapp is not a function
- [Solved] vue3vite Error: Failed to resolve import “@vue/server-renderer from “src\App.vue“. Does the file exist
- [Solved] Vue Error: Module build failed: Error: No PostCSS Config found in
- [Solved] VUE eslint Error: Expected linebreaks to be ‘LF‘ but found ‘CRLF