<template>
<div>
<p>{{msg}}</p> // hello Vue
<p>{{reverseMsg}}</p> // euV olleh
</div>
</template>
<script lang="ts">
import { defineComponent,reactive,computed } from 'vue'
export default defineComponent({
setup() {
const state = reactive({
msg: 'hello Vue'
})
// 计算属性
const reverseMsg = computed(() => {
return state.msg.split('').reverse().join('')
})
return {
...state,
reverseMsg
}
},
})
</script>
- 不可修改的computed const reverseMsg = computed(() => {})
- 可修改的computed const reverseMsg = computed({get () {},set () {}})