我正在尝试在VueJs中使用computed
字段。
以前它是可以实现的:
{
props: {
left: 5,
right: 100,
},
computed: {
width: () {return this.right.value - this.left.value};
}
}
但是有了新的SFC/Composition语法,我该怎么做呢?
<script setup>
defineProps({left: 5, right: 100});
defineComputed( //??
)
</script>
我读过这个链接,但它没有解释:https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md
在新的设置语法中,使用computed
创建一个计算属性:
import { computed } from 'vue'
const props = defineProps({left: 5, right: 100});
const width = computed(() => props.right - props.left);