The vue path is divided into:
Absolute path, relative path, ~+ path and alias+ path
Absolute path:
(1) Content placed in the public folder will not be processed through webpack and can be directly referenced.
For example: put it directly in the public folder, no matter which file it is in, you can reference it like this
<img src="" style="width: 200px; height: 200px" />
(2) Quote by alias
In js, introducing a file path with an alias does not need to be added before the alias. The path introduced in css or style needs to be added before the path, and the path starts with ~. The subsequent part will be regarded as module dependencies. This means that you can use this feature to reference a resource in a Node dependency, ~ equivalent to requirement.
Defined alias in chainWebpack: (config) => { .set('@', resolve('src')) //The alias of this project path src path is @ .set('_conf', resolve('src/config')) //The alias of this project path src/config path is set to _conf .set('_iconfont', resolve('src/assets/icons/iconfont')) .set('_css', resolve('src/assets/css/')) .set('_img', resolve('src/assets/img/')) .set('_js', resolve('src/assets/js/')) .set('_components', resolve('src/components')) .set('_header', 'src/Header') .set('_footer', 'src/Footer') } existvueIntroducedjsFiles andcssdocument NoticeexistscriptThere is no front of the path~ <script> import index from "_js/"; ==src/assets/js/ import "swiper/"; ==node_modules/swiper/ import "_js/vendor/swiper/"; ==src/assets/js/vendor/swiper/ </script> NoticestyleThe path using alias needs to be added before~ <style scoped> @import url(~_css/); ==src/assets/css/ </style>
Relative path:
Introduce relative paths, require before the path
existsrc/view/home/Introducedsrc/assets/img/ Correct writing: <img src="require(../../assets/img/)" /> Wrong writing: <img src="../../assets/img/" /> reason:Apart frompublicContents under the folder,The rest of the content will passwebpackdeal with,The path changes,So need to userequiredeal with一下路径
~+path and alias+path
The following example introduces a file by alias
Set by aliasdivBackground picture usereqiure,This way you can write <div class="thumbnail" v-bind:style= "{backgroundImage:'url(' +require('_img/index/') +')',}" > use~,This won't work: <div class="thumbnail" v-bind:style= "{backgroundImage:'url(~_img/index/)',}" >
Givedivset upstylestyle,set up背景图片等属性 <div class="featurette" :style="[ { background: 'url(' + require('_img/index/') + ' ) bottom center no-repeat', }, { 'background-size': 'auto 100%', }, { 'margin-bottom': '50px', }, ]" > </div>
Introduce pictures by alias <img src="~_img/index/" alt="" />
Introduced by aliascss <style scoped> @import url("~_css/"); </style>
Introduced by aliasjs <script> import index from "_js/"; import Swiper from "swiper"; import "swiper/"; //The heel is oppositeimport "_js/vendor/swiper/"; </script>
This is the article about the issue of citing file paths in vue. For more related contents of citing file paths in vue, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!