vue中在data中引入图片的路径方法
作者:互联网
错误的引入方式:
export default { data () { return{ imgUrl_homePage:'@/assets/img/homePage_active.png' } } }
因为webpack是按字符号打包的,正确的引入方式:
1.import在外部引入
import img_url from '@/assets/img/homePage_active.png' export default { data () { return{ imgUrl_homePage:img_url } } }
2.require内部引入
export default { data () { return{ imgUrl_homePage:require('@/assets/img/homePage_active.png') } } }
参考---https://blog.csdn.net/qq_36485978/article/details/84821416?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.base&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.base
标签:vue,return,img,data,路径,blog,export,homePage 来源: https://www.cnblogs.com/pwindy/p/14933784.html