VUE3+setup报错解决Getting a value from the `props` in root scope of `<script setup>` will cause the valu
在vue3+setup使用props传值报错Getting a value from the `props` in root scope of `` will cause the value to lose reactivity.
·
<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去接收
更多推荐
已为社区贡献3条内容
所有评论(0)