Author -  Sai gowtham

How to concatenate two strings in Vue

In this tutorial, we are going to learn about how to concatenate two strings in Vue.js with the help of examples.

Consider, we have a following img string and url string in Vue code:

<template>
  <div id="app">
    <img src="" />
  </div>
</template>

<script>
export default {
  data(){
    url: "https://reactgo.com"
    img: "/img/car.png"
  }
};
</script>

Now, we need to concatenate above two strings.

Concatenating two strings in Vue

To concatenate the two strings in vue, we can use the v-bind directive followed by the two strings.

The v-bind directive dynamically binds attribute to a javascript expression.

Here is an example:

<template>
  <div id="app">
    <img v-bind:src="url + img" />
  </div>
</template>

<script>
export default {
  data(){
    url: "https://reactgo.com"
    img: "/img/car.png"
  }
};
</script>

In the above code, we have used v-bind directive to bind attribute to a JavaScript variable and we have used the plus + to join the two strings.

Similarly, we can use the es6 template literals to concatenate the strings in Vue.

<template>
  <div id="app">
    <img v-bind:src="`${url}/img/car.png`" />
  </div>
</template>

<script>
export default {
  data(){
    url: "https://reactgo.com"
  }
};
</script>

we can also use the short hand property of v-bind directive like this:

<img :src="url + img" />

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY