<div id="example">
{{ message.split('').reverse().join('') }}
</div>
Example1
<html>
<head>
<title>Vue.js Computed Property</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="com_props">
This is the Original message:<h2> {{ message }}</h2>
This is the Computed reversed message: <h2> {{ reversedMessage }}</h2>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#com_props',
data: {
message: 'Hello lidihuo'
},
computed: {
// a computed getter
reversedMessage: function () {
// `this` points to the vm instance
return this.message.split('').reverse().join('')
}
}
})
html, body {
margin: 5px;
padding: 0;
}
data: {
message: 'Hello lidihuo'
},
computed: {
// a computed getter
reversedMessage: function () {
<html>
<head>
<title>Vue.js Computed Property</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "com_props">
FirstName : <input type = "text" v-model = "firstname" /> <br/><br/>
LastName : <input type = "text" v-model = "lastname"/> <br/><br/>
<h2>My name is {{firstname}} {{lastname}}</h2>
<h2>Retrieve name by using computed property : {{getfullname}}</h2>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#com_props',
data: {
firstname :"",
lastname :"",
birthyear : ""
},
computed :{
getfullname : function(){
return this.firstname +" "+ this.lastname;
}
}
})
html, body {
margin: 5px;
padding: 0;
}
computed :{
getfullname : function(){
return this.firstname +" "+ this.lastname;
}
}
<html>
<head>
<title>Vue.js Computed Property</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "com_props">
<h2 style = "background-color:gray;">Random No from computed property: {{getrandomno}}</h2>
<h2>Random No from method: {{getrandomno1()}}</h2>
<h2 style = "background-color:gray;">Random No from computed property: {{getrandomno}}</h2>
<h2 style = "background-color:gray;">Random No from computed property: {{getrandomno}}</h2>
<h2>Random No from method: {{getrandomno1()}}</h2>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#com_props',
data: {
name : "helloworld"
},
methods: {
getrandomno1 : function() {
return Math.random();
}
},
computed :{
getrandomno : function(){
return Math.random();
}
}
})
html, body {
margin: 5px;
padding: 0;
}
<html>
<head>
<title>Vue.js Computed Property</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "com_props">
<input type = "text" v-model = "fullname" />
<h1>{{firstName}}</h1>
<h1>{{lastName}}</h1>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#com_props',
data: {
firstName : "Alex",
lastName : "Junior"
},
methods: {
},
computed :{
fullname : {
get : function() {
return this.firstName+" "+this.lastName;
}
}
}
})
<h1>{{firstName}}</h1>
<h1>{{lastName}}</h1>
computed :{
fullname : {
get : function() {
return this.firstName+" "+this.lastName;
},
set : function(name) {
var fname = name.split("");
this.firstName = fname[0];
this.lastName = fname[1]
}
}
}
<html>
<head>
<title>Vue.js Computed Property</title>
<link rel="stylesheet" href="index.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id = "com_props">
<input type = "text" v-model = "fullname" />
<h1>{{firstName}}</h1>
<h1>{{lastName}}</h1>
</div>
<script src="index.js"></script>
</body>
</html>
var vm = new Vue({
el: '#com_props',
data: {
firstName : "Alex",
lastName : "Junior"
},
methods: {
},
computed :{
fullname : {
get : function() {
return this.firstName+" "+this.lastName;
},
set : function(name) {
var fname = name.split("");
this.firstName = fname[0];
this.lastName = fname[1]
}
}
}
});