【问题标题】:Fetch image from folder and database in Vuejs and Nodejs从 Vuejs 和 Nodejs 中的文件夹和数据库中获取图像
【发布时间】:2021-09-19 19:35:02
【问题描述】:
This is my fetch Api, In the data which was fetch by the code below I have a picture name saved into the database

async mounted() {
const id = this.$route.params.id;
this.profiles = (await this.$api.get(`/profile/${id}`)).data;
},

file: "\"2021-09-17T15-06-07.540Z-phenell logo white.png\"" //The picture name in database while the image it self is saved into a folder in my backend folder. Am using quasar (Vuejs) for fontend and Expressjs for backend. 

所以我试图从文件夹中获取图像并将其与数据库中的名称连接起来。

app.use(express.static(path.join(__dirname, 'public'))); //I already set my static folder.

我要获取的 VueJs 代码

      <div class="host text-center"> 
          <img class="profile-user-img img-fluid img-circle" :src="getProfilePhoto()" alt="User profile picture">
      </div>

methods: {
 getProfilePhoto() {
    return "http://localhost:8081/public/images/"+this.profiles.file
 }

},

但是我得到一个 404 Not found 的错误

http://localhost:8081/public/images/undefined 404(未找到) http://localhost:8081/public/images/%222021-09-17T15-06-07.540Z-phenell%20logo%20white.png

【问题讨论】:

    标签: node.js vue.js multer quasar


    【解决方案1】:

    试试这个方法:

    getProfilePhoto() {
      return require(`http://localhost:8081/public/images/${this.profiles.file}`)
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-15
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 2014-12-11
    • 1970-01-01
    相关资源
    最近更新 更多