<script lang="ts" setup>
import { computed } from 'vue';
type Props = {
  A: string;
  B: string;
};
const props = defineProps<Props>();

const A = computed(() => {
  return props.A;
});
const B = computed(() => {
  return props.B;
});
</script>

在使用props时,直接获取props的值,如const A=props.A报错Getting a value from the `props` in root scope of `<script setup>` will cause the value to lose reactivity.,那么使用计算属性就好了。

本质是Vue采用单向数据流,我们不能直接去更改props的值,需要去使用computed去接收

Logo

前往低代码交流专区

更多推荐