Vue.js String Replace

We can use native javascript string replace function to replace a value in string. Here in this tutorial, we are going to explain how you can use replace method in VueJS. You can also use our online editor to edit and run the code online.

Vue.js String Replace Example

Here is an example of replace function in vue.js. –


<!DOCTYPE html>
 <script src=""></script>
<div id="app">
	<div id="myId" ref="myId">{{ message }}</div>
	<button @click="myFunction()">Click Me</button>
 new Vue({
el: '#app',
  data: { 
	  message:"Welcome to Canada!"
    myFunction: function () {
		this.message = this.message.replace("Canada", "France");


Try it »

On the same way you can use this function to replace a value or pattern.

Output of above example-

Vue.Js String Replace function example


Add Comment

📖 Read More