Vue CLI +静态资产+指令

问题描述 投票:0回答:1

我在这里关注指南:Vue CLI - include image from assets folder in static file

所以在assets文件夹中我有img\pic.jpg。我可以使用普通的html和css调用该图像:

<img src="~@/assets/img/pic.jpg">

<style scoped>
.app {
  background: url(~@/assets/img/pic.jpg);
}
</style>

但对于指令(纠正我,如果这个词是错误的),我试过这个,当然也失败了。你能帮我吗?

<img :src="'~@/assets/'+user.profilepic">

//Note:  user.profilepic = "img/pic.jpg"
vuejs2 directive vue-cli-3
1个回答
1
投票

你能试试吗?

<img :src="require(`@/assets/${user.profilepic}`)" />
© www.soinside.com 2019 - 2024. All rights reserved.