[ADD]计算属性
This commit is contained in:
parent
d86c6ecf5b
commit
ce7af5ac23
|
@ -0,0 +1,64 @@
|
|||
<!DOCTYPE html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Page Title</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="">
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!--[if lt IE 7]>
|
||||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
<div id="example">
|
||||
<p>Original Message: "{{ message }}"</p>
|
||||
<p>Computed reversed Message: "{{reversedMessage}}"</p>
|
||||
</div>
|
||||
|
||||
<div id="demo">
|
||||
<h3>{{ fullName }}</h3>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
var app = new Vue({
|
||||
el: '#example',
|
||||
data: {
|
||||
message: 'Hello Vue!'
|
||||
},
|
||||
computed: {
|
||||
reversedMessage: function(){
|
||||
return this.message.split('').reverse().join('')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var vm = new Vue({
|
||||
el: '#demo',
|
||||
data: {
|
||||
firstName: 'foo',
|
||||
lastName: 'bar',
|
||||
},
|
||||
computed: {
|
||||
fullName: {
|
||||
get: function(){
|
||||
return this.firstName + ' ' + this.lastName
|
||||
},
|
||||
set: function(newValue){
|
||||
var names = newValue.split(' ')
|
||||
this.firstName = names[0]
|
||||
this.lastName = names[names.length - 1]
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue