D
D
Daksin2021-10-21 15:14:51
Vue.js
Daksin, 2021-10-21 15:14:51

How to replace localhost:8000 with my domain?

617159567e12a072212915.png
I need to add my domain to /files/image on the production version.
For example: www.mydomain.com/files/imagename.
What do I need to add to vue config?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
RuMsg, 2021-11-03
@Daksin

<template>
  <div>
    <div v-for="(image, index) in images" :key="index">
      <img :src="image_url(image)" >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      domain_name: '//www.mydomain.com',
      images: [
        "files/image1.jpeg",
        "files/image2.jpeg",
        "files/image3.jpeg"
      ]
    };
  },

  computed: {

    image_url: function(path) {
      return process.env.NODE_ENV === 'production'
      ? `${this.domain_name}/${path}`
      : `/${path}`;
    }

  }
}
</script>

A
Aetae, 2021-10-21
@Aetae

Well, change publicPath for production, what's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question