<div id="app">
<!-- Mastache语法拼接 -->
<p>{{firstName}}{{lastName}}</p>
<!-- 使用方法methods -->
<p>{{fullName()}}</p>
<!-- 使用计算属性computed -->
<p>{{fullName1}}</p>
</div>
<script>
new Vue({
el: "#app",
data: {
firstName: 'zhang',
lastName: 'san'
},
methods: {
fullName() {
return this.firstName + this.lastName
}
},
computed: {
fullName1() {
return this.firstName + this.lastName
}
}
})
</script>
计算属性computed看起来和方法似乎一样,只是方法调用需要使用(),而计算属性不用,方法取名字一般是动词见名知义,而计算属性是属性是名词,这都是基本使用。