1. <template>
    2. <div>
    3. <p>{{msg}}</p> // hello Vue
    4. <p>{{reverseMsg}}</p> // euV olleh
    5. </div>
    6. </template>
    7. <script lang="ts">
    8. import { defineComponent,reactive,computed } from 'vue'
    9. export default defineComponent({
    10. setup() {
    11. const state = reactive({
    12. msg: 'hello Vue'
    13. })
    14. // 计算属性
    15. const reverseMsg = computed(() => {
    16. return state.msg.split('').reverse().join('')
    17. })
    18. return {
    19. ...state,
    20. reverseMsg
    21. }
    22. },
    23. })
    24. </script>
    1. 不可修改的computed const reverseMsg = computed(() => {})
    2. 可修改的computed const reverseMsg = computed({get () {},set () {}})