Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
my background-image property is not concatenating properly

I have some code I am using with vuejs that binds a domain as well as an additional snippet that should get added to the domain. I cant seem to figure out the proper concatenation when it comes to the domain and item.url

var vm = new Vue({
        el: '#app',
        data: {
           items:[],
          domain:"https://example.com/"
        },
           
         },
        mounted: function () {
           
            })
        },
        
        })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id ="app">
<div v-for="item in items" class="gallery-cell" v-bind:style="{ backgroundImage: 'url('+ domain + item.url + ')' }">{{ item.text}}</div>
</div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your Vue declaration is a total mess.
After fixing it background image is concatenated as it should

new Vue({
    el: '#app',
    data: {
        items: [
            { text: 'test1', url: 'ac0/cat-1364386.jpg' },
            { text: 'test2', url: '867/volcanic-mt-ngauruhoe-1378772.jpg' },
            { text: 'test3', url: '981/cow-1380252.jpg' }
        ],
        domain: "https://images.freeimages.com/images/large-previews/"
    }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
    <div v-for="item in items"
         v-bind:style="{ backgroundImage: 'url('+ domain + item.url + ')' }"
         class="gallery-cell">
        {{ item.text }}
    </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

I would highly recommend to use template strings for better readability. And it's recommended to use a method and not doing your background image path building within your template.

new Vue({
  el: '#app',
  data: {
    items: [
      { text: 'a', url: '10096730/pexels-photo-10096730.jpeg' },
      { text: 'b', url: '9772527/pexels-photo-9772527.jpeg' },
    ],
    domain: 'https://images.pexels.com/photos/'
  },
  methods: {
    getBackgroundImageStyle(url) {
      return `backgroundImage: url(${this.domain}${url})`;
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id ="app">
  <div 
    class="gallery-cell"
    v-for="item in items" 
    :style="getBackgroundImageStyle(item.url)">
    {{ item.text }}
  </div>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda