Vue.js img src concatenate variable and text

Vue.js img src concatenate variable and text

Asked on November 17, 2018 in vue.js.
Add Comment


  • 2 Answer(s)

    Don’t use curly braces or tags in the attribute value.
    To Concatenate the variable, try the below code:

    <img v-bind:src="imgPreUrl + 'img/logo.png'">
    
    

    Or the simple type

    <img :src="imgPreUrl + 'img/logo.png'">
    
    
    Answered on November 17, 2018.
    Add Comment

    In another case I’m able to use template literal ES6 with backticks, so for yours could be set as:
    Other cases, you can use an ES6 pattern with backslashes:

    <img v-bind:src="`${imgPreUrl()}img/logo.png`">
    
    

     

    Answered on November 17, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.