vue3计算属性以及赋值
<template>
<!-- 计算属性比如分页器就会使用到 -->
<h1>计算属性</h1>
<!-- 此时obj.hobby.length是大于0的,所以页面的list为yes -->
<h3>{{ list }}</h3>
<button @click="getList">获取list的值 ==>{{ val }}</button>
</template>
<script setup>
import {ref, reactive, computed } from "vue";
const obj = reactive({
todo: '吃饭',
hobby: ['打篮球', '打乒乓球', '踢足球']
})
const val = ref(null)
const list = computed(() => {
return obj.hobby.length > 0 ? "yes" : 'no'
})
const getList = () => {
console.log(list.value);
val.value = list.value
}
</script>