在Vue 3的setup()函数中,可以使用props来接收父组件传递的数据。你可以像下面这样来接收selectedData属性:

import { ref } from 'vue';

export default {
  props: ['selectedData'],
  setup(props) {
    // 使用ref()将props.selectedData包装成响应式对象
    const selectedData = ref(props.selectedData);

    // 在这里可以使用selectedData

    return {
      selectedData
    };
  }
}

setup()函数中,我们通过参数props来获取父组件传递的属性。然后使用ref()props.selectedData包装成响应式对象,并将其返回。

现在,你就可以在组件中使用selectedData了,并且当父组件传递的selectedData发生变化时,组件也会相应地更新

vue3 setup里如何接收export default props selectedData

原文地址: https://www.cveoy.top/t/topic/iXIt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录