Vue.js String Slice


This method is basically used to extract a part of string from a string. We can use the native slice function to extract a part of string from a string. Here in this tutorial, we are going to explain how you can use the string slice method in vuejs. You can also use our online editor to edit and run the code online.


Vue.js String Slice Method Example

You can use slice method simply as below-

Example:

<!DOCTYPE html>
<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
</head>
<body>
<div id="app">
	<div id="myId" ref="myId">{{ message }}</div>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  message:"Welcome to Canada!"
  },
  
   methods:{
    myFunction: function () {
		
		this.message = this.message.slice(1, 5);
		
    }
	}

});
</script>        
</body>
</html>

Try it »

If you run the above example it will produce output something like this-

Vue.js String Slice Method Example


Advertisements

Add Comment

📖 Read More