组件的计算name
属性未定义
<template>
<div class="person">
<p>{{name}}</p>
</div>
</template>
<script>
export default {
name: 'person',
data () {
return {
firstName: 'John',
lastName: 'Doe',
}
},
computed: {
name: () => {
return `${this.firstName} ${this.lastName}`
}
}
}
</script>
导致 undefined undefined
答案 0 :(得分:0)
我已经有类似的问题,因为计算机必须有这样的setter和getter:
computed: {
fullName: {
// getter
get: function () {
return this.firstName + ' ' + this.lastName
},
// setter
set: function (newValue) {
var names = newValue.split(' ')
this.firstName = names[0]
this.lastName = names[names.length - 1]
}
}
}